diff --git a/services/BUILD.gn b/services/BUILD.gn index 0a1a186ed7f2609a50558bd2c6556c8a5dfe61f7..eec3de75811764a188622a8d505aeb95d94a4bfc 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -186,11 +186,13 @@ if (os_level == "mini" || os_level == "small") { sources += net_observer_files } sources += permission_adapter_files + sources += identity_service_files sources += hiview_adapter_files defines = deviceauth_defines defines += [ "HILOG_ENABLE" ] defines += [ "DEV_AUTH_HIVIEW_ENABLE" ] defines += [ "DEV_AUTH_PERMISSION_ENABLE" ] + defines += [ "DEV_AUTH_IS_ENABLE" ] cflags = build_flags cflags += [ "-DDEV_AUTH_WORK_THREAD_STACK_SIZE=${device_auth_hichain_thread_stack_size}", diff --git a/services/data_manager/cred_data_manager/inc/cred_tlv_parser.h b/services/data_manager/cred_data_manager/inc/cred_tlv_parser.h new file mode 100644 index 0000000000000000000000000000000000000000..4a4f0b591e7edd7232f25ee443239d4bc46732b5 --- /dev/null +++ b/services/data_manager/cred_data_manager/inc/cred_tlv_parser.h @@ -0,0 +1,321 @@ +/* + * Copyright (C) 2025 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 CRED_TLV_PARSER_H +#define CRED_TLV_PARSER_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define USE_DEFAULT_TAG 0xFFFF +#define CRED_TLV_FAIL (-1) +#define NO_REVERT 0 +#define NEED_REVERT 1 +#define MAX_TOTOL_LEN (100 * 1024 * 1024) + +typedef struct CredTlvBaseT { + unsigned short tag; + unsigned int length; + unsigned short checkTag; + unsigned short hasValue; + int64_t (*parse)(struct CredTlvBaseT *, HcParcel *, HcBool); + int64_t (*getlen)(struct CredTlvBaseT *); + int64_t (*encode)(struct CredTlvBaseT *, HcParcel *); + void (*deinit)(struct CredTlvBaseT *); +} CredTlvBase; + +#define DECLARE_CRED_TLV_STRUCT(x) \ + CredTlvBase base; \ + unsigned int offsetCount; \ + unsigned int offset[x]; + +unsigned short GetCredTag(unsigned short checkTag, unsigned short defaultTag); + +#define BEGIN_CRED_TLV_STRUCT_DEFINE(TlvS, CheckTag) \ +void Init##TlvS(TlvS *tlv, unsigned short checkTag) \ +{ \ + typedef TlvS TlvStructType; \ + unsigned int index = 0; \ + (void)memset_s(&tlv->base, sizeof(tlv->base), 0, sizeof(tlv->base)); \ + tlv->base.checkTag = GetCredTag(checkTag, CheckTag); + +#define CRED_TLV_MEMBER_OPTION(TlvMember, TlvMemberName, CheckTag) \ + Init##TlvMember(&tlv->TlvMemberName, CheckTag); \ + tlv->TlvMemberName.base.option = 1; \ + tlv->offset[index++] = offsetof(TlvStructType, TlvMemberName); + +#define CRED_TLV_MEMBER(TlvMember, TlvMemberName, CheckTag) \ + Init##TlvMember(&tlv->TlvMemberName, CheckTag); \ + tlv->offset[index++] = offsetof(TlvStructType, TlvMemberName); + +#define END_CRED_TLV_STRUCT_DEFINE(void) \ + tlv->offsetCount = index; \ + tlv->base.parse = ParseCredTlvStruct; \ + tlv->base.getlen = GetLenCredTlvStruct; \ + tlv->base.encode = EncodeCredTlvStruct; \ + tlv->base.deinit = DeinitCredTlvStruct; \ +} + +#define DECLARE_CRED_TLV_FIX_LENGTH_TYPE(TlvName, TypeName) \ +typedef struct \ +{ \ + CredTlvBase base; \ + TypeName data; \ +} TlvName; + +DECLARE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvInt32, int) +DECLARE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvInt16, short) +DECLARE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvInt8, char) +DECLARE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvUint32, uint32_t) +DECLARE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvUint16, uint16_t) +DECLARE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvUint8, uint8_t) +DECLARE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvUint64, uint64_t) +DECLARE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvInt64, uint64_t) + +#define DEFINE_CRED_TLV_FIX_LENGTH_TYPE(TlvName, Revert) \ +int64_t ParseCredTlv##TlvName(CredTlvBase *tlv, HcParcel *parcel, HcBool strict) \ +{ \ + (void)strict; \ + TlvName *realTlv = (TlvName *)(tlv); \ + HcBool readRet = HC_FALSE; \ + if (tlv->length != sizeof(realTlv->data)) \ + { \ + return CRED_TLV_FAIL; \ + } \ +\ + if (Revert) \ + { \ + readRet = ParcelReadRevert(parcel, &realTlv->data, sizeof(realTlv->data)); \ + } else { \ + readRet = ParcelRead(parcel, &realTlv->data, sizeof(realTlv->data)); \ + } \ + if (readRet) \ + { \ + return tlv->length; \ + } else { \ + return CRED_TLV_FAIL; \ + } \ +} \ +\ +int64_t GetLenCredTlv##TlvName(CredTlvBase *tlv) \ +{ \ + TlvName *realTlv = (TlvName *)(tlv); \ + return (int64_t)sizeof(realTlv->data); \ +} \ +\ +int64_t EncodeCredTlv##TlvName(CredTlvBase *tlv, HcParcel *parcel) \ +{ \ + HcBool writeRet = HC_FALSE; \ + TlvName *realTlv = (TlvName *)(tlv); \ + if (Revert) \ + { \ + writeRet = ParcelWriteRevert(parcel, &realTlv->data, sizeof(realTlv->data)); \ + } else { \ + writeRet = ParcelWrite(parcel, &realTlv->data, sizeof(realTlv->data)); \ + } \ + if (writeRet) \ + { \ + return sizeof(realTlv->data); \ + } else { \ + return CRED_TLV_FAIL; \ + } \ +} \ +\ +DECLARE_CRED_TLV_PARSE_FUNC(TlvName, ParseCredTlv##TlvName, GetLenCredTlv##TlvName, EncodeCredTlv##TlvName); + +void DeinitCredTlvFixMember(CredTlvBase *tlv); + +#define DECLARE_CRED_TLV_PARSE_FUNC(TlvName, TlvParseFunc, TlvGetLenFunc, TlvEncodeFunc) \ +void Init##TlvName(TlvName *tlv, unsigned short checkTag) \ +{ \ + (void)memset_s(&tlv->base, sizeof(tlv->base), 0, sizeof(tlv->base)); \ + tlv->base.parse = TlvParseFunc; \ + tlv->base.getlen = TlvGetLenFunc; \ + tlv->base.encode = TlvEncodeFunc; \ + tlv->base.deinit = DeinitCredTlvFixMember; \ + tlv->base.checkTag = checkTag; \ +} + +#define CRED_TLV_INIT(TlvName, TlvData) Init##TlvName(TlvData, USE_DEFAULT_TAG); + +#define CRED_TLV_DEINIT(TlvData) TlvData.base.deinit((CredTlvBase *)(&TlvData)); +typedef struct { + CredTlvBase base; + unsigned int offsetCount; + unsigned int offset[0]; +} CredTlvOffsetExample; + +HcBool ParseCredTlvHead(CredTlvBase *tlv, HcParcel *parcel); +int64_t ParseCredTlvNode(CredTlvBase *tlv, HcParcel *parcel, HcBool strict); +int64_t GetlenCredTlvNode(CredTlvBase *tlv); +void DeinitCredTlvNode(CredTlvBase *tlv); + +int64_t ParseCredTlvStruct(CredTlvBase *tlv, HcParcel *parcel, HcBool strict); +int64_t EncodeCredTlvStruct(CredTlvBase *tlv, HcParcel *parcel); +int64_t GetLenCredTlvStruct(CredTlvBase *tlv); +void DeinitCredTlvStruct(CredTlvBase *tlv); +int64_t EncodeCredTlvNode(CredTlvBase *tlv, HcParcel *parcel, HcBool isRoot); +HcBool DecodeCredTlvMessage(CredTlvBase *msg, HcParcel *parcel, HcBool strict); +HcBool EncodeCredTlvMessage(CredTlvBase *msg, HcParcel *parcel); + +typedef struct { + CredTlvBase base; + HcParcel data; +} CredTlvBuffer; + +void InitCredTlvBuffer(CredTlvBuffer *tlv, unsigned short checkTag); +int64_t ParseCredTlvBuffer(CredTlvBase *tlv, HcParcel *parcel, HcBool strict); +int64_t GetlenCredTlvBuffer(CredTlvBase *tlv); +int64_t EncodeCredTlvBuffer(CredTlvBase *tlv, HcParcel *parcel); +void DeinitCredTlvBuffer(CredTlvBase *tlv); + +typedef struct { + CredTlvBase base; + HcString data; +} CredTlvString; + +void InitCredTlvString(CredTlvString *tlv, unsigned short checkTag); +int64_t ParseCredTlvString(CredTlvBase *tlv, HcParcel *parcel, HcBool strict); +int64_t GetlenCredTlvString(CredTlvBase *tlv); +int64_t EncodeCredTlvString(CredTlvBase *tlv, HcParcel *parcel); +void DeinitCredTlvString(CredTlvBase *tlv); + +#define DECLEAR_CRED_INIT_FUNC(TlvStruct) \ +void Init##TlvStruct(TlvStruct *tlv, unsigned short checkTag); + +DECLEAR_CRED_INIT_FUNC(CredTlvUint64) +DECLEAR_CRED_INIT_FUNC(CredTlvUint32) +DECLEAR_CRED_INIT_FUNC(CredTlvUint16) +DECLEAR_CRED_INIT_FUNC(CredTlvUint8) +DECLEAR_CRED_INIT_FUNC(CredTlvInt64) +DECLEAR_CRED_INIT_FUNC(CredTlvInt32) +DECLEAR_CRED_INIT_FUNC(CredTlvInt16) +DECLEAR_CRED_INIT_FUNC(CredTlvInt8) + +#define DECLARE_CRED_TLV_VECTOR(TlvVecName, TlvVecElement) \ +DECLARE_HC_VECTOR(Vec##TlvVecName, TlvVecElement) \ +typedef struct { \ + CredTlvBase base; \ + Vec##TlvVecName data; \ +} TlvVecName; \ +void DeinitTlv##TlvVecName(CredTlvBase *tlv); \ +void Init##TlvVecName(TlvVecName *tlv, unsigned short checkTag); + +#define IMPLEMENT_CRED_TLV_VECTOR(TlvVecName, TlvElementName, VecAllocCount) \ +IMPLEMENT_HC_VECTOR(Vec##TlvVecName, TlvElementName, VecAllocCount) \ +int64_t ParseTlv##TlvVecName(CredTlvBase *tlv, HcParcel *parcel, HcBool strict) \ +{ \ + TlvVecName *realTlv = (TlvVecName *)(tlv); \ + uint32_t count = 0; \ + if (!ParcelReadUint32(parcel, &count)) { \ + return CRED_TLV_FAIL; \ + } \ + int64_t totalLen = sizeof(count); \ + uint32_t index = 0; \ + for (index = 0; index < count; ++index) { \ + TlvElementName tlvElement; \ + TlvElementName *curElement = realTlv->data.pushBack(&realTlv->data, &tlvElement); \ + if (curElement == NULL) { \ + return CRED_TLV_FAIL; \ + } \ + CRED_TLV_INIT(TlvElementName, curElement); \ +\ + int64_t elementLen = ParseCredTlvNode((CredTlvBase *)curElement, parcel, strict); \ + if (elementLen < 0) { \ + return CRED_TLV_FAIL; \ + } \ + totalLen += elementLen; \ + if (totalLen >= MAX_TOTOL_LEN) { \ + return CRED_TLV_FAIL; \ + } \ + } \ +\ + return totalLen; \ +} \ +\ +int64_t EncodeTlv##TlvVecName(CredTlvBase *tlv, HcParcel *parcel) \ +{ \ + TlvVecName *realTlv = (TlvVecName *)(tlv); \ + uint32_t index = 0; \ + TlvElementName *element = NULL; \ + int64_t totalLen = 4; \ + uint32_t count = realTlv->data.size(&realTlv->data); \ + if (!ParcelWriteUint32(parcel, count)) { \ + return CRED_TLV_FAIL; \ + } \ +\ + FOR_EACH_HC_VECTOR(realTlv->data, index, element) { \ + if (element != NULL) { \ + int64_t len = EncodeCredTlvNode((CredTlvBase *)element, parcel, HC_FALSE); \ + totalLen += len; \ + if (totalLen >= MAX_TOTOL_LEN) { \ + return CRED_TLV_FAIL; \ + } \ + } \ + } \ + return totalLen; \ +} \ +int64_t GetLenTlv##TlvVecName(CredTlvBase *tlv) \ +{ \ + TlvVecName *realTlv = (TlvVecName *)(tlv); \ + uint32_t index = 0; \ + TlvElementName *element = NULL; \ + int64_t totalLen = sizeof(int32_t); \ + FOR_EACH_HC_VECTOR(realTlv->data, index, element) { \ + if (element != NULL) { \ + totalLen += GetlenCredTlvNode((CredTlvBase *)element); \ + if (totalLen >= MAX_TOTOL_LEN) { \ + return CRED_TLV_FAIL; \ + } \ + } else { \ + return CRED_TLV_FAIL; \ + } \ + } \ + return totalLen; \ +} \ +\ +void DeinitTlv##TlvVecName(CredTlvBase *tlv) \ +{ \ + TlvVecName *realTlv = (TlvVecName *)(tlv); \ + uint32_t index = 0; \ + TlvElementName *element = NULL; \ + FOR_EACH_HC_VECTOR(realTlv->data, index, element) { \ + if (element != NULL) { \ + CRED_TLV_DEINIT((*element)); \ + } \ + } \ + DESTROY_HC_VECTOR(Vec##TlvVecName, &((TlvVecName *)tlv)->data); \ +} \ +\ +void Init##TlvVecName(TlvVecName *tlv, unsigned short checkTag) \ +{ \ + (void)memset_s(&tlv->base, sizeof(tlv->base), 0, sizeof(tlv->base)); \ + tlv->base.parse = ParseTlv##TlvVecName; \ + tlv->base.encode = EncodeTlv##TlvVecName; \ + tlv->base.getlen = GetLenTlv##TlvVecName; \ + tlv->base.deinit = DeinitTlv##TlvVecName; \ + tlv->base.checkTag = checkTag; \ + tlv->data = CREATE_HC_VECTOR(Vec##TlvVecName); \ +} + +#ifdef __cplusplus +} +#endif +#endif diff --git a/services/data_manager/cred_data_manager/inc/credential_data_manager.h b/services/data_manager/cred_data_manager/inc/credential_data_manager.h index a1925d563de6ed8c86dbee821dbbf8ced87344f5..446d2a377daadc5262390d72249f0ab9a57123bc 100644 --- a/services/data_manager/cred_data_manager/inc/credential_data_manager.h +++ b/services/data_manager/cred_data_manager/inc/credential_data_manager.h @@ -17,10 +17,8 @@ #define CREDENTIAL_DATA_MANAGER_H #include -#include "hc_string.h" #include "hc_string_vector.h" -#include "hc_tlv_parser.h" -#include "hc_vector.h" +#include "cred_tlv_parser.h" #include "json_utils.h" #define MAX_STRING_LEN 256 diff --git a/services/data_manager/cred_data_manager/src/cred_tlv_parser.c b/services/data_manager/cred_data_manager/src/cred_tlv_parser.c new file mode 100644 index 0000000000000000000000000000000000000000..e82cb84809eb120e448c400fa49e41a7435cde12 --- /dev/null +++ b/services/data_manager/cred_data_manager/src/cred_tlv_parser.c @@ -0,0 +1,462 @@ +/* + * Copyright (C) 2025 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 "cred_tlv_parser.h" +#include + +#define MAX_CRED_TLV_LENGTH (4800 * 1024) + +HcBool ParseCredTlvHead(CredTlvBase *tlv, HcParcel *parcel) +{ +#ifdef IS_BIG_ENDIAN + if (!ParcelReadUint16Revert(parcel, &tlv->tag)) { + return HC_FALSE; + } +#else + if (!ParcelReadUint16(parcel, &tlv->tag)) { + return HC_FALSE; + } +#endif + + if (tlv->tag != tlv->checkTag) { + return HC_FALSE; + } +#ifdef IS_BIG_ENDIAN + if (!ParcelReadUint32Revert(parcel, &tlv->length)) { + return HC_FALSE; + } +#else + if (!ParcelReadUint32(parcel, &tlv->length)) { + return HC_FALSE; + } +#endif + if (tlv->length > MAX_CRED_TLV_LENGTH) { + return HC_FALSE; + } + return HC_TRUE; +} + +int64_t ParseCredTlvNode(CredTlvBase *tlv, HcParcel *parcel, HcBool strict) +{ + if (!ParseCredTlvHead(tlv, parcel)) { + return CRED_TLV_FAIL; + } else { + if (GetParcelDataSize(parcel) < tlv->length) { + return CRED_TLV_FAIL; + } + + int64_t ret = tlv->parse(tlv, parcel, strict); + if (ret < 0 || ret > MAX_CRED_TLV_LENGTH) { + return CRED_TLV_FAIL; + } else { + return ret + sizeof(tlv->tag) + sizeof(tlv->length); + } + } +} + +int64_t GetlenCredTlvNode(CredTlvBase *tlv) +{ + int64_t bodyLen = tlv->getlen(tlv); + if (bodyLen < 0 || bodyLen > MAX_CRED_TLV_LENGTH) { + return CRED_TLV_FAIL; + } else { + tlv->length = bodyLen + sizeof(tlv->tag) + sizeof(tlv->length); + return tlv->length; + } +} + +void DeinitCredTlvNode(CredTlvBase *tlv) +{ + if (tlv != NULL) { + tlv->deinit(tlv); + } +} + +int64_t EncodeCredTlvNode(CredTlvBase *tlv, HcParcel *parcel, HcBool isRoot) +{ + int64_t bodyLen = tlv->getlen(tlv); + if (bodyLen < 0 || bodyLen > MAX_CRED_TLV_LENGTH) { + return CRED_TLV_FAIL; + } else if (bodyLen == 0) { + if (isRoot) { + ResetParcel(parcel, sizeof(uint16_t) + sizeof(uint32_t), 0); + } +#ifdef IS_BIG_ENDIAN + ParcelWriteUint16Revert(parcel, tlv->checkTag); + ParcelWriteUint32Revert(parcel, bodyLen); +#else + ParcelWriteUint16(parcel, tlv->checkTag); + ParcelWriteUint32(parcel, bodyLen); +#endif + return sizeof(tlv->tag) + sizeof(tlv->length); + } else { // has value + if (isRoot) { + ResetParcel(parcel, sizeof(uint16_t) + sizeof(uint32_t) + bodyLen, 0); + } + int64_t encodeLen; + tlv->length = (uint32_t)bodyLen; +#ifdef IS_BIG_ENDIAN + ParcelWriteUint16Revert(parcel, tlv->checkTag); + ParcelWriteUint32Revert(parcel, tlv->length); +#else + ParcelWriteUint16(parcel, tlv->checkTag); + ParcelWriteUint32(parcel, tlv->length); +#endif + encodeLen = tlv->encode(tlv, parcel); + if (encodeLen < 0 || encodeLen > MAX_CRED_TLV_LENGTH) { + return CRED_TLV_FAIL; + } else { + return encodeLen + sizeof(tlv->tag) + sizeof(tlv->length); + } + } +} + +static CredTlvBase* GetEmptyStructNode(CredTlvBase *tlv, unsigned short tag) +{ + if (tlv == NULL) { + return NULL; + } + + unsigned int index; + unsigned int memberCount = *(unsigned int *)((char *)tlv + offsetof(CredTlvOffsetExample, offsetCount)); + unsigned int *offset = (unsigned int *)((char *)tlv + offsetof(CredTlvOffsetExample, offset)); + for (index = 0; index < memberCount; ++index) { + CredTlvBase *tlvChild = (CredTlvBase *)(((char *)tlv) + offset[index]); + if (tlvChild->checkTag == tag && tlvChild->hasValue == 0) { + return tlvChild; + } + } + + return NULL; +} + +static int64_t CheckStructNodeAllHasValue(CredTlvBase *tlv) +{ + if (tlv == NULL) { + return 0; + } else { + unsigned int index; + unsigned int memberCount = *(unsigned int *)((char *)tlv + offsetof(CredTlvOffsetExample, offsetCount)); + unsigned int *offset = (unsigned int *)((char *)tlv + offsetof(CredTlvOffsetExample, offset)); + for (index = 0; index < memberCount; ++index) { + CredTlvBase *tlvChild = (CredTlvBase *)(((char *)tlv) + offset[index]); + if (tlvChild->hasValue == 0) { + return -1; + } + } + } + + return 0; +} + +static void SetStructNodeHasValue(CredTlvBase *tlv) +{ + if (tlv != NULL) { + tlv->hasValue = 1; + } +} + +static int64_t ParseAndSkipTlvUnknownNode(HcParcel *parcel) +{ + // read tag + uint16_t tag = 0; + if (!ParcelReadUint16(parcel, &tag)) { + return CRED_TLV_FAIL; + } + + // read length + uint32_t length = 0; + if (!ParcelReadUint32(parcel, &length)) { + return CRED_TLV_FAIL; + } + + // pop data + if (!ParcelPopFront(parcel, length)) { + return CRED_TLV_FAIL; + } + + return sizeof(tag) + sizeof(length) + length; +} + +int64_t ParseCredTlvStruct(CredTlvBase *tlv, HcParcel *parcel, HcBool strict) +{ + int64_t childTotalLength = 0; + do { + uint16_t tag = 0; + if (!ParcelReadWithoutPopData(parcel, &tag, sizeof(tag))) { + return CRED_TLV_FAIL; + } + CredTlvBase *tlvChild = GetEmptyStructNode(tlv, tag); + if (tlvChild == NULL) { + if (strict) { + return CRED_TLV_FAIL; + } + + int64_t unknownChildLength = ParseAndSkipTlvUnknownNode(parcel); + if (unknownChildLength < 0 || unknownChildLength > MAX_CRED_TLV_LENGTH) { + return CRED_TLV_FAIL; + } + childTotalLength += unknownChildLength; + if (childTotalLength > MAX_CRED_TLV_LENGTH) { + return CRED_TLV_FAIL; + } + } else { + int64_t childLength = ParseCredTlvNode(tlvChild, parcel, strict); + if (childLength < 0 || childLength > MAX_CRED_TLV_LENGTH) { + return CRED_TLV_FAIL; + } + SetStructNodeHasValue(tlvChild); + childTotalLength += childLength; + if (childTotalLength > MAX_CRED_TLV_LENGTH) { + return CRED_TLV_FAIL; + } + } + } while (childTotalLength < tlv->length); + + if (childTotalLength > tlv->length) { + return CRED_TLV_FAIL; + } + + if (strict && CheckStructNodeAllHasValue(tlv) != 0) { + return CRED_TLV_FAIL; + } + + return childTotalLength; +} + +int64_t EncodeCredTlvStruct(CredTlvBase *tlv, HcParcel *parcel) +{ + unsigned int index; + unsigned int memberCount = *(unsigned int *)((char *)tlv + offsetof(CredTlvOffsetExample, offsetCount)); + unsigned int *offset = (unsigned int *)((char *)tlv + offsetof(CredTlvOffsetExample, offset)); + + uint32_t totalLen = 0; + for (index = 0; index < memberCount; ++index) { + CredTlvBase *tlvChild = (CredTlvBase *)(((char *)tlv) + offset[index]); + int64_t childLen = EncodeCredTlvNode(tlvChild, parcel, HC_FALSE); + if (childLen < 0 || childLen > MAX_CRED_TLV_LENGTH) { + return CRED_TLV_FAIL; + } else { + totalLen += childLen; + } + if (totalLen > MAX_CRED_TLV_LENGTH) { + return CRED_TLV_FAIL; + } + } + + return totalLen; +} + +int64_t GetLenCredTlvStruct(CredTlvBase *tlv) +{ + unsigned int index; + unsigned int memberCount = *(unsigned int *)((char *)tlv + offsetof(CredTlvOffsetExample, offsetCount)); + unsigned int *offset = (unsigned int *)((char *)tlv + offsetof(CredTlvOffsetExample, offset)); + int64_t childTotalLength = 0; + + for (index = 0; index < memberCount; ++index) { + CredTlvBase *tlvChild = (CredTlvBase *)(((char *)tlv) + offset[index]); + int64_t childLength = GetlenCredTlvNode(tlvChild); + if (childLength <= 0 || childLength > MAX_CRED_TLV_LENGTH) { + return CRED_TLV_FAIL; + } else { + childTotalLength += childLength; + } + if (childTotalLength > MAX_CRED_TLV_LENGTH) { + return CRED_TLV_FAIL; + } + } + + return childTotalLength; +} + +void DeinitCredTlvStruct(CredTlvBase *tlv) +{ + unsigned int index; + unsigned int memberCount = *(unsigned int *)((char *)tlv + offsetof(CredTlvOffsetExample, offsetCount)); + unsigned int *offset = (unsigned int *)((char *)tlv + offsetof(CredTlvOffsetExample, offset)); + + for (index = 0; index < memberCount; ++index) { + CredTlvBase *tlvChild = (CredTlvBase *)(((char *)tlv) + offset[index]); + DeinitCredTlvNode(tlvChild); + } +} + +HcBool DecodeCredTlvMessage(CredTlvBase *msg, HcParcel *parcel, HcBool strict) +{ + if (msg == NULL || parcel == NULL) { + return HC_FALSE; + } else { + int64_t msgLen = ParseCredTlvNode(msg, parcel, strict); + if (msgLen > MAX_CRED_TLV_LENGTH) { + return HC_FALSE; + } + if ((int64_t)(msg->length + sizeof(msg->length) + sizeof(msg->tag)) != msgLen) { + return HC_FALSE; + } + + if (GetParcelDataSize(parcel) != 0) { + return HC_FALSE; + } + } + + return HC_TRUE; +} + + +HcBool EncodeCredTlvMessage(CredTlvBase *msg, HcParcel *parcel) +{ + if (msg == NULL || parcel == NULL) { + return HC_FALSE; + } else { + if (EncodeCredTlvNode(msg, parcel, HC_TRUE) < 0) { + return HC_FALSE; + } + } + + return HC_TRUE; +} + +int64_t ParseCredTlvBuffer(CredTlvBase *tlv, HcParcel *parcel, HcBool strict) +{ + (void)strict; + CredTlvBuffer *realTlv = (CredTlvBuffer *)(tlv); + if (tlv->length == 0 || ParcelReadParcel(parcel, &realTlv->data, tlv->length, HC_FALSE)) { + return tlv->length; + } else { + return CRED_TLV_FAIL; + } +} + +int64_t GetlenCredTlvBuffer(CredTlvBase *tlv) +{ + CredTlvBuffer *realTlv = (CredTlvBuffer *)(tlv); + return (int64_t)GetParcelDataSize(&realTlv->data); +} + +int64_t EncodeCredTlvBuffer(CredTlvBase *tlv, HcParcel *parcel) +{ + CredTlvBuffer *realTlv = (CredTlvBuffer *)(tlv); + int64_t len = GetlenCredTlvBuffer(tlv); + if (len <= 0 || len > MAX_CRED_TLV_LENGTH) { + return CRED_TLV_FAIL; + } + + if (ParcelReadParcel(&realTlv->data, parcel, len, HC_TRUE)) { + return len; + } else { + return CRED_TLV_FAIL; + } +} + +void DeinitCredTlvBuffer(CredTlvBase *tlv) +{ + DeleteParcel(&((CredTlvBuffer *)tlv)->data); +} + +void InitCredTlvBuffer(CredTlvBuffer *tlv, unsigned short checkTag) +{ + (void)memset_s(&tlv->base, sizeof(tlv->base), 0, sizeof(tlv->base)); + tlv->base.parse = ParseCredTlvBuffer; + tlv->base.getlen = GetlenCredTlvBuffer; + tlv->base.encode = EncodeCredTlvBuffer; + tlv->base.deinit = DeinitCredTlvBuffer; + tlv->base.checkTag = checkTag; + tlv->data = CreateParcel(PARCEL_DEFAULT_LENGTH, PARCEL_DEFAULT_ALLOC_UNIT); +} + +int64_t ParseCredTlvString(CredTlvBase *tlv, HcParcel *parcel, HcBool strict) +{ + (void)strict; + CredTlvString *realTlv = (CredTlvString *)(tlv); + ClearParcel(&realTlv->data.parcel); + if (tlv->length == 0 || ParcelReadParcel(parcel, &realTlv->data.parcel, tlv->length, HC_FALSE)) { + return tlv->length; + } else { + return CRED_TLV_FAIL; + } +} + +int64_t GetlenCredTlvString(CredTlvBase *tlv) +{ + CredTlvString *realTlv = (CredTlvString *)(tlv); + return (int64_t)GetParcelDataSize(&realTlv->data.parcel); +} + +int64_t EncodeCredTlvString(CredTlvBase *tlv, HcParcel *parcel) +{ + CredTlvString *realTlv = (CredTlvString *)(tlv); + int64_t len = GetlenCredTlvString(tlv); + if (len <= 0 || len > MAX_CRED_TLV_LENGTH) { + return CRED_TLV_FAIL; + } + + if (ParcelReadParcel(&realTlv->data.parcel, parcel, len, HC_TRUE)) { + return len; + } else { + return CRED_TLV_FAIL; + } +} + +void DeinitCredTlvString(CredTlvBase *tlv) +{ + DeleteString(&((CredTlvString*)tlv)->data); +} + +void InitCredTlvString(CredTlvString *tlv, unsigned short checkTag) +{ + (void)memset_s(&tlv->base, sizeof(tlv->base), 0, sizeof(tlv->base)); + tlv->base.parse = ParseCredTlvString; + tlv->base.getlen = GetlenCredTlvString; + tlv->base.encode = EncodeCredTlvString; + tlv->base.deinit = DeinitCredTlvString; + tlv->base.checkTag = checkTag; + tlv->data = CreateString(); +} + +unsigned short GetCredTag(unsigned short checkTag, unsigned short defaultTag) +{ + if (checkTag == USE_DEFAULT_TAG) { + return defaultTag; + } else { + return checkTag; + } +} + +void DeinitCredTlvFixMember(CredTlvBase* tlv) +{ + (void)tlv; + return; +} + +#ifdef IS_BIG_ENDIAN +DEFINE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvInt64, NEED_REVERT) +DEFINE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvInt32, NEED_REVERT) +DEFINE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvInt16, NEED_REVERT) +DEFINE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvInt8, NEED_REVERT) +DEFINE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvUint64, NEED_REVERT) +DEFINE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvUint32, NEED_REVERT) +DEFINE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvUint16, NEED_REVERT) +DEFINE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvUint8, NEED_REVERT) +#else +DEFINE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvInt64, NO_REVERT) +DEFINE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvInt32, NO_REVERT) +DEFINE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvInt16, NO_REVERT) +DEFINE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvInt8, NO_REVERT) +DEFINE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvUint64, NO_REVERT) +DEFINE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvUint32, NO_REVERT) +DEFINE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvUint16, NO_REVERT) +DEFINE_CRED_TLV_FIX_LENGTH_TYPE(CredTlvUint8, NO_REVERT) +#endif diff --git a/services/data_manager/cred_data_manager/src/credential_data_manager.c b/services/data_manager/cred_data_manager/src/credential_data_manager.c index ac17f26d5853310d86514ab5d1fa818ee52dc3bd..a75259d4ced6f785b6d6b651bfa936da138b9121 100644 --- a/services/data_manager/cred_data_manager/src/credential_data_manager.c +++ b/services/data_manager/cred_data_manager/src/credential_data_manager.c @@ -30,60 +30,60 @@ #include "cred_listener.h" typedef struct { - DECLARE_TLV_STRUCT(17) - TlvString credId; - TlvString deviceId; - TlvString peerUserSpaceId; - TlvUint8 subject; - TlvString userId; - TlvUint8 issuer; - TlvUint8 credType; - TlvUint8 keyFormat; - TlvUint8 algorithmType; - TlvUint8 proofType; - TlvBuffer authorizedAccountList; - TlvBuffer authorizedAppList; - TlvBuffer authorizedDeviceList; - TlvUint8 authorizedScope; - TlvString credOwner; - TlvInt32 ownerUid; - TlvString extendInfo; + DECLARE_CRED_TLV_STRUCT(17) + CredTlvString credId; + CredTlvString deviceId; + CredTlvString peerUserSpaceId; + CredTlvUint8 subject; + CredTlvString userId; + CredTlvUint8 issuer; + CredTlvUint8 credType; + CredTlvUint8 keyFormat; + CredTlvUint8 algorithmType; + CredTlvUint8 proofType; + CredTlvBuffer authorizedAccountList; + CredTlvBuffer authorizedAppList; + CredTlvBuffer authorizedDeviceList; + CredTlvUint8 authorizedScope; + CredTlvString credOwner; + CredTlvInt32 ownerUid; + CredTlvString extendInfo; } TlvCredentialElement; -DECLEAR_INIT_FUNC(TlvCredentialElement) -DECLARE_TLV_VECTOR(TlvCredentialVec, TlvCredentialElement) +DECLEAR_CRED_INIT_FUNC(TlvCredentialElement) +DECLARE_CRED_TLV_VECTOR(TlvCredentialVec, TlvCredentialElement) typedef struct { - DECLARE_TLV_STRUCT(2) - TlvInt32 version; + DECLARE_CRED_TLV_STRUCT(2) + CredTlvInt32 version; TlvCredentialVec credentials; } HCCredDataBaseV1; -DECLEAR_INIT_FUNC(HCCredDataBaseV1) - -BEGIN_TLV_STRUCT_DEFINE(TlvCredentialElement, 0x0001) - TLV_MEMBER(TlvString, credId, 0x4001) - TLV_MEMBER(TlvString, deviceId, 0x4002) - TLV_MEMBER(TlvString, peerUserSpaceId, 0x4003) - TLV_MEMBER(TlvUint8, subject, 0x4004) - TLV_MEMBER(TlvString, userId, 0x4005) - TLV_MEMBER(TlvUint8, issuer, 0x4006) - TLV_MEMBER(TlvUint8, credType, 0x4007) - TLV_MEMBER(TlvUint8, keyFormat, 0x4008) - TLV_MEMBER(TlvUint8, algorithmType, 0x4009) - TLV_MEMBER(TlvUint8, proofType, 0x400A) - TLV_MEMBER(TlvBuffer, authorizedAccountList, 0x400B) - TLV_MEMBER(TlvBuffer, authorizedAppList, 0x400C) - TLV_MEMBER(TlvBuffer, authorizedDeviceList, 0x400D) - TLV_MEMBER(TlvUint8, authorizedScope, 0x400E) - TLV_MEMBER(TlvString, credOwner, 0x400F) - TLV_MEMBER(TlvInt32, ownerUid, 0x4010) - TLV_MEMBER(TlvString, extendInfo, 0x4011) -END_TLV_STRUCT_DEFINE() -IMPLEMENT_TLV_VECTOR(TlvCredentialVec, TlvCredentialElement, 1) - -BEGIN_TLV_STRUCT_DEFINE(HCCredDataBaseV1, 0x0001) - TLV_MEMBER(TlvInt32, version, 0x6001) - TLV_MEMBER(TlvCredentialVec, credentials, 0x6002) -END_TLV_STRUCT_DEFINE() +DECLEAR_CRED_INIT_FUNC(HCCredDataBaseV1) + +BEGIN_CRED_TLV_STRUCT_DEFINE(TlvCredentialElement, 0x0001) + CRED_TLV_MEMBER(CredTlvString, credId, 0x4001) + CRED_TLV_MEMBER(CredTlvString, deviceId, 0x4002) + CRED_TLV_MEMBER(CredTlvString, peerUserSpaceId, 0x4003) + CRED_TLV_MEMBER(CredTlvUint8, subject, 0x4004) + CRED_TLV_MEMBER(CredTlvString, userId, 0x4005) + CRED_TLV_MEMBER(CredTlvUint8, issuer, 0x4006) + CRED_TLV_MEMBER(CredTlvUint8, credType, 0x4007) + CRED_TLV_MEMBER(CredTlvUint8, keyFormat, 0x4008) + CRED_TLV_MEMBER(CredTlvUint8, algorithmType, 0x4009) + CRED_TLV_MEMBER(CredTlvUint8, proofType, 0x400A) + CRED_TLV_MEMBER(CredTlvBuffer, authorizedAccountList, 0x400B) + CRED_TLV_MEMBER(CredTlvBuffer, authorizedAppList, 0x400C) + CRED_TLV_MEMBER(CredTlvBuffer, authorizedDeviceList, 0x400D) + CRED_TLV_MEMBER(CredTlvUint8, authorizedScope, 0x400E) + CRED_TLV_MEMBER(CredTlvString, credOwner, 0x400F) + CRED_TLV_MEMBER(CredTlvInt32, ownerUid, 0x4010) + CRED_TLV_MEMBER(CredTlvString, extendInfo, 0x4011) +END_CRED_TLV_STRUCT_DEFINE() +IMPLEMENT_CRED_TLV_VECTOR(TlvCredentialVec, TlvCredentialElement, 1) + +BEGIN_CRED_TLV_STRUCT_DEFINE(HCCredDataBaseV1, 0x0001) + CRED_TLV_MEMBER(CredTlvInt32, version, 0x6001) + CRED_TLV_MEMBER(TlvCredentialVec, credentials, 0x6002) +END_CRED_TLV_STRUCT_DEFINE() IMPLEMENT_HC_VECTOR(CredentialVec, Credential*, 1) @@ -332,17 +332,17 @@ static bool ReadCredInfoFromParcel(HcParcel *parcel, OsAccountCredInfo *info) { bool ret = false; HCCredDataBaseV1 dbv1; - TLV_INIT(HCCredDataBaseV1, &dbv1) - if (DecodeTlvMessage((TlvBase *)&dbv1, parcel, false)) { + CRED_TLV_INIT(HCCredDataBaseV1, &dbv1) + if (DecodeCredTlvMessage((CredTlvBase *)&dbv1, parcel, false)) { if (!LoadCredentials(&dbv1, &info->credentials)) { - TLV_DEINIT(dbv1) + CRED_TLV_DEINIT(dbv1) return false; } ret = true; } else { LOGE("[CRED#DB]: Decode Tlv Message Failed!"); } - TLV_DEINIT(dbv1) + CRED_TLV_DEINIT(dbv1) return ret; } @@ -588,9 +588,9 @@ static bool SaveCredentials(const CredentialVec *vec, HCCredDataBaseV1 *db) if (element == NULL) { return false; } - TLV_INIT(TlvCredentialElement, element); + CRED_TLV_INIT(TlvCredentialElement, element); if (!SetCredentialElement(element, *entry)) { - TLV_DEINIT((*element)); + CRED_TLV_DEINIT((*element)); return false; } } @@ -601,19 +601,19 @@ static bool SaveCredInfoToParcel(const OsAccountCredInfo *info, HcParcel *parcel { int32_t ret = false; HCCredDataBaseV1 dbv1; - TLV_INIT(HCCredDataBaseV1, &dbv1) + CRED_TLV_INIT(HCCredDataBaseV1, &dbv1) dbv1.version.data = 1; do { if (!SaveCredentials(&info->credentials, &dbv1)) { break; } - if (!EncodeTlvMessage((TlvBase *)&dbv1, parcel)) { + if (!EncodeCredTlvMessage((CredTlvBase *)&dbv1, parcel)) { LOGE("[CRED#DB]: Encode Tlv Message failed!"); break; } ret = true; } while (0); - TLV_DEINIT(dbv1) + CRED_TLV_DEINIT(dbv1) return ret; } @@ -1121,8 +1121,8 @@ static void DumpDb(int fd, const OsAccountCredInfo *db) { const CredentialVec *credentials = &db->credentials; dprintf(fd, "|----------------------------------CRED-DataBase-----------------------------------|\n"); - dprintf(fd, "|%-13s = %-67d|\n", "osAccountId", db->osAccountId); - dprintf(fd, "|%-13s = %-67d|\n", "credentialNum", credentials->size(credentials)); + dprintf(fd, "|%-13s = %-66d|\n", "osAccountId", db->osAccountId); + dprintf(fd, "|%-13s = %-66d|\n", "credentialNum", credentials->size(credentials)); uint32_t index; Credential **credential; FOR_EACH_HC_VECTOR(*credentials, index, credential) { diff --git a/services/device_auth.c b/services/device_auth.c index 5429dc5a6db7894da4a7d775c3148898fd98c45c..be31feaa06c8f0daa1d237a522cd615d0f72d5cb 100644 --- a/services/device_auth.c +++ b/services/device_auth.c @@ -21,7 +21,6 @@ #include "common_defs.h" #include "ext_plugin_manager.h" #include "group_data_manager.h" -#include "credential_data_manager.h" #include "dev_auth_module_manager.h" #include "dev_session_mgr.h" #include "group_manager.h" @@ -43,11 +42,17 @@ #include "identity_manager.h" #include "group_auth_manager.h" #include "account_task_manager.h" +#ifdef DEV_AUTH_IS_ENABLE +#include "credential_data_manager.h" +#endif static GroupAuthManager *g_groupAuthManager = NULL; static DeviceGroupManager *g_groupManagerInstance = NULL; + +#ifdef DEV_AUTH_IS_ENABLE static CredManager *g_credManager = NULL; static CredAuthManager *g_credAuthManager = NULL; +#endif typedef struct { HcTaskBase base; @@ -983,6 +988,7 @@ static int32_t AddDeviceIdToJson(CJson *context, const char *peerUdid) return HC_SUCCESS; } +#ifdef DEV_AUTH_IS_ENABLE static int32_t QueryAndAddCredToContext(int32_t osAccountId, CJson *context, const char *credIdKey, const char *credObjKey) { @@ -1021,6 +1027,7 @@ static int32_t QueryAndAddAllCredToContext(int32_t osAccountId, CJson *context) } return HC_SUCCESS; } +#endif static const char *GetAppIdByContext(const CJson *context, bool isCredAuth) { @@ -1087,9 +1094,11 @@ static int32_t BuildServerAuthContext(int64_t requestId, CJson *context, bool is return HC_ERR_JSON_ADD; } if (isCredAuth) { +#ifdef DEV_AUTH_IS_ENABLE if ((res = QueryAndAddAllCredToContext(osAccountId, context)) != HC_SUCCESS) { return res; } +#endif } const char *appId = GetAppIdByContext(context, isCredAuth); if (appId == NULL) { @@ -1309,6 +1318,7 @@ static int32_t ProcessData(int64_t authReqId, const uint8_t *data, uint32_t data return res; } +#ifdef DEV_AUTH_IS_ENABLE static int32_t BuildClientAuthCredContext(int32_t osAccountId, int64_t requestId, const char *appId, CJson *context) { if (AddBoolToJson(context, FIELD_IS_BIND, false) != HC_SUCCESS) { @@ -1457,6 +1467,7 @@ static int32_t ProcessCredData(int64_t authReqId, const uint8_t *data, uint32_t } return res; } +#endif static void CancelRequest(int64_t requestId, const char *appId) { @@ -1674,6 +1685,7 @@ static void DestroyGmAndGa(void) } } +#ifdef DEV_AUTH_IS_ENABLE static int32_t AllocCredentialMgr(void) { if (g_credManager == NULL) { @@ -1714,6 +1726,17 @@ static void DestroyCa(void) } } +static int32_t InitIdentityServiceIneer() +{ + int32_t res = InitIdentityService(); + if (res != HC_SUCCESS) { + DestroyIdentityService(); + return HC_ERROR; + } + return HC_SUCCESS; +} +#endif + static int32_t InitAllModules(void) { int32_t res = GetLoaderInstance()->initAlg(); @@ -1736,9 +1759,11 @@ static int32_t InitAllModules(void) if ((res = InitGroupManager()) != HC_SUCCESS) { goto CLEAN_CALLBACK; } - if ((res = InitIdentityService()) != HC_SUCCESS) { - goto CLEAN_IDENTITY_SERVICE; +#ifdef DEV_AUTH_IS_ENABLE + if ((res = InitIdentityServiceIneer()) != HC_SUCCESS) { + return res; } +#endif if ((res = InitDevSessionManager()) != HC_SUCCESS) { goto CLEAN_GROUP_MANAGER; } @@ -1758,8 +1783,6 @@ CLEAN_MODULE: DestroyModules(); CLEAN_CRED: DestroyCredMgr(); -CLEAN_IDENTITY_SERVICE: - DestroyIdentityService(); return res; } @@ -1866,6 +1889,7 @@ DEVICE_AUTH_API_PUBLIC int InitDeviceAuthService(void) if (res != HC_SUCCESS) { return res; } +#ifdef DEV_AUTH_IS_ENABLE res = AllocCa(); if (res != HC_SUCCESS) { DestroyGmAndGa(); @@ -1877,12 +1901,15 @@ DEVICE_AUTH_API_PUBLIC int InitDeviceAuthService(void) DestroyCa(); return res; } +#endif InitOsAccountAdapter(); res = InitAllModules(); if (res != HC_SUCCESS) { DestroyGmAndGa(); +#ifdef DEV_AUTH_IS_ENABLE DestroyCa(); DestroyCredentialMgr(); +#endif return res; } INIT_PERFORMANCE_DUMPER(); @@ -1903,11 +1930,15 @@ DEVICE_AUTH_API_PUBLIC void DestroyDeviceAuthService(void) DestroyTaskManager(); DestroyDevSessionManager(); DestroyGroupManager(); +#ifdef DEV_AUTH_IS_ENABLE DestroyIdentityService(); +#endif DestroyGmAndGa(); DestroyAccountTaskManager(); +#ifdef DEV_AUTH_IS_ENABLE DestroyCa(); DestroyCredentialMgr(); +#endif DestroyModules(); DestroyCredMgr(); DestroyChannelManager(); @@ -1967,6 +1998,7 @@ DEVICE_AUTH_API_PUBLIC const GroupAuthManager *GetGaInstance(void) return g_groupAuthManager; } +#ifdef DEV_AUTH_IS_ENABLE DEVICE_AUTH_API_PUBLIC const CredManager *GetCredMgrInstance(void) { if (g_credManager == NULL) { @@ -1997,4 +2029,5 @@ DEVICE_AUTH_API_PUBLIC const CredAuthManager *GetCredAuthInstance(void) g_credAuthManager->processCredData = ProcessCredData; g_credAuthManager->authCredential = AuthCredential; return g_credAuthManager; -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/services/deviceauth.gni b/services/deviceauth.gni index 0c745722b3b4e3bb5c49dacd3d71fe2fdf7d6fd7..d900dca0c09df77dca1036c9acca5f9bdb30a2ad 100644 --- a/services/deviceauth.gni +++ b/services/deviceauth.gni @@ -31,11 +31,18 @@ identity_service_path = "${services_path}/identity_service" enable_broadcast = true deviceauth_defines = [] -identity_service_inc = [ "${identity_service_path}/inc" ] +identity_service_inc = [ + "${identity_service_path}/inc", + "${cred_data_manager_path}/inc", + "${cred_listener_path}/inc", +] identity_service_files = [ "${identity_service_path}/src/identity_service.c", "${identity_service_path}/src/identity_operation.c", "${identity_service_path}/src/identity_service_impl.c", + "${cred_data_manager_path}/src/credential_data_manager.c", + "${cred_data_manager_path}/src/cred_tlv_parser.c", + "${cred_listener_path}/src/cred_listener.c", ] inc_path = [ @@ -44,8 +51,6 @@ inc_path = [ "${ext_plugin_manager_path}/inc", "${ext_plugin_manager_path}/inc/account_related", "${group_data_manager_path}/inc", - "${cred_data_manager_path}/inc", - "${cred_listener_path}/inc", "${privacy_enhancement_path}/inc", "${group_auth_path}/inc", "${group_auth_path}/inc/account_unrelated_group_auth", @@ -170,8 +175,6 @@ ext_plugin_manager_files = group_database_manager_files = [ "${group_data_manager_path}/src/group_data_manager.c" ] -cred_database_manager_files = - [ "${cred_data_manager_path}/src/credential_data_manager.c" ] privacy_enhancement_files = [ "${privacy_enhancement_path}/src/pseudonym_manager.c" ] @@ -292,8 +295,6 @@ broadcast_manager_mock_files = [ "${group_manager_path}/src/broadcast_manager_mock/broadcast_manager_mock.c", ] -cred_listener_files = [ "${cred_listener_path}/src/cred_listener.c" ] - deviceauth_files = dev_frameworks_files + deviceauth_common_files + session_manager_files + creds_manager_files @@ -360,8 +361,7 @@ if (enable_p2p_pake_dl_prime_len_256 == true) { } deviceauth_files += group_auth_files + group_manager_files + - group_database_manager_files + ext_plugin_manager_files + - cred_database_manager_files + identity_service_files + group_database_manager_files + ext_plugin_manager_files account_unrelated_deviceauth = enable_p2p_bind_lite_protocol || enable_p2p_auth_lite_protocol || @@ -430,9 +430,9 @@ if (device_auth_enable_soft_bus_channel == true) { } if (enable_broadcast == true) { - deviceauth_files += broadcast_manager_files + cred_listener_files + deviceauth_files += broadcast_manager_files } else { - deviceauth_files += broadcast_manager_mock_files + cred_listener_files + deviceauth_files += broadcast_manager_mock_files } if (!defined(ohos_lite) && (!defined(global_parts_info) || diff --git a/services/frameworks/src/plugin_adapter/ext_part/account_lifecycle_plugin_proxy.c b/services/frameworks/src/plugin_adapter/ext_part/account_lifecycle_plugin_proxy.c index f31cefa9f60e1aca8e0f4729462a4a5cb827b26a..ece548fd99d789ebc623c157b4139a1986ac51bc 100644 --- a/services/frameworks/src/plugin_adapter/ext_part/account_lifecycle_plugin_proxy.c +++ b/services/frameworks/src/plugin_adapter/ext_part/account_lifecycle_plugin_proxy.c @@ -126,7 +126,7 @@ static int32_t InitAccountLifecyclePluginCtx(void) g_accountPluginCtx = NULL; return HC_ERR_INVALID_PARAMS; } - +#ifdef DEV_AUTH_IS_ENABLE const CredManager *cmInstace = GetCredMgrInstance(); if (cmInstace == NULL) { LOGE("[ACCOUNT_LIFE_PLUGIN]: Cm instance is null."); @@ -134,7 +134,13 @@ static int32_t InitAccountLifecyclePluginCtx(void) g_accountPluginCtx = NULL; return HC_ERR_INVALID_PARAMS; } - + g_accountPluginCtx->addCredential = cmInstace->addCredential; + g_accountPluginCtx->exportCredential = cmInstace->exportCredential; + g_accountPluginCtx->deleteCredential = cmInstace->deleteCredential; + g_accountPluginCtx->updateCredInfo = cmInstace->updateCredInfo; + g_accountPluginCtx->queryCredInfoByCredId = cmInstace->queryCredInfoByCredId; + g_accountPluginCtx->queryCredentialByParams = cmInstace->queryCredentialByParams; +#endif g_accountPluginCtx->createGroup = gmInstace->createGroup; g_accountPluginCtx->deleteGroup = gmInstace->deleteGroup; g_accountPluginCtx->getGroupInfo = gmInstace->getGroupInfo; @@ -144,12 +150,6 @@ static int32_t InitAccountLifecyclePluginCtx(void) g_accountPluginCtx->executeWorkerTask = ExecuteWorkerTask; g_accountPluginCtx->notifyAsyncTaskStart = NotifyAsyncTaskStart; g_accountPluginCtx->notifyAsyncTaskStop = NotifyAsyncTaskStop; - g_accountPluginCtx->addCredential = cmInstace->addCredential; - g_accountPluginCtx->exportCredential = cmInstace->exportCredential; - g_accountPluginCtx->deleteCredential = cmInstace->deleteCredential; - g_accountPluginCtx->updateCredInfo = cmInstace->updateCredInfo; - g_accountPluginCtx->queryCredInfoByCredId = cmInstace->queryCredInfoByCredId; - g_accountPluginCtx->queryCredentialByParams = cmInstace->queryCredentialByParams; return HC_SUCCESS; } diff --git a/test/fuzztest/devauthfunc_fuzzer/BUILD.gn b/test/fuzztest/devauthfunc_fuzzer/BUILD.gn index 025d1645751aa7de8b181889164b866e48ecdb9d..b3bdd10f1a218772034766c0c39a72a8973542e3 100644 --- a/test/fuzztest/devauthfunc_fuzzer/BUILD.gn +++ b/test/fuzztest/devauthfunc_fuzzer/BUILD.gn @@ -55,10 +55,7 @@ ohos_fuzztest("DevAuthFuncFuzzTest") { sources += dev_frameworks_files sources += deviceauth_common_files - sources += identity_service_files - sources += cred_listener_files sources += group_database_manager_files - sources += cred_database_manager_files sources += ext_plugin_manager_files sources += session_manager_files sources += session_v1_files diff --git a/test/fuzztest/group_auth/account_related/accountrelatedgroupauth_fuzzer/BUILD.gn b/test/fuzztest/group_auth/account_related/accountrelatedgroupauth_fuzzer/BUILD.gn index 386a64738e9e4818600da2072f6223f0ceb2f403..2a72ce74484b34c8f3cf9254a966dd083fdb1b1e 100644 --- a/test/fuzztest/group_auth/account_related/accountrelatedgroupauth_fuzzer/BUILD.gn +++ b/test/fuzztest/group_auth/account_related/accountrelatedgroupauth_fuzzer/BUILD.gn @@ -60,11 +60,8 @@ ohos_fuzztest("AccountRelatedGroupAuthFuzzTest") { sources += dev_frameworks_files sources += deviceauth_common_files sources += group_database_manager_files - sources += cred_database_manager_files sources += ext_plugin_manager_files sources += session_manager_files - sources += identity_service_files - sources += cred_listener_files sources += session_v1_files sources += session_v2_files sources += iso_protocol_files diff --git a/test/fuzztest/identityservice_fuzzer/BUILD.gn b/test/fuzztest/identityservice_fuzzer/BUILD.gn index 8bd0928dd58500620f577003177c12e630821ca2..dbe96f58c9dd9e2300234ab9b6ff192faab9f701 100644 --- a/test/fuzztest/identityservice_fuzzer/BUILD.gn +++ b/test/fuzztest/identityservice_fuzzer/BUILD.gn @@ -60,10 +60,8 @@ ohos_fuzztest("IdentityServiceFuzzTest") { sources += dev_frameworks_files sources += deviceauth_common_files sources += group_database_manager_files - sources += cred_database_manager_files sources += ext_plugin_manager_files sources += session_manager_files - sources += cred_listener_files sources += identity_service_files sources += session_v1_files sources += session_v2_files @@ -128,6 +126,7 @@ ohos_fuzztest("IdentityServiceFuzzTest") { "DEV_AUTH_FUNC_TEST", "ENABLE_PSEUDONYM", "DEV_AUTH_HIVIEW_ENABLE", + "DEV_AUTH_IS_ENABLE", "DEV_AUTH_PERMISSION_ENABLE", ] diff --git a/test/unittest/deviceauth/BUILD.gn b/test/unittest/deviceauth/BUILD.gn index a3b80e89e597f85ebb9ad9918d36ae14f791d484..e85a8a4014047ff17d10f04a2f04c0d4e8e8192e 100644 --- a/test/unittest/deviceauth/BUILD.gn +++ b/test/unittest/deviceauth/BUILD.gn @@ -54,9 +54,6 @@ ohos_unittest("deviceauth_llt") { sources += dev_frameworks_files sources += deviceauth_common_files sources += group_database_manager_files - sources += cred_database_manager_files - sources += cred_listener_files - sources += identity_service_files sources += ext_plugin_manager_files sources += session_manager_files sources += session_v1_files @@ -178,11 +175,8 @@ ohos_unittest("device_auth_func_test") { sources += dev_frameworks_files sources += deviceauth_common_files sources += group_database_manager_files - sources += cred_database_manager_files sources += ext_plugin_manager_files sources += session_manager_files - sources += cred_listener_files - sources += identity_service_files sources += session_v1_files sources += session_v2_files sources += iso_protocol_files @@ -314,10 +308,8 @@ ohos_unittest("device_auth_identity_service_test") { sources += dev_frameworks_files sources += deviceauth_common_files sources += group_database_manager_files - sources += cred_database_manager_files sources += ext_plugin_manager_files sources += session_manager_files - sources += cred_listener_files sources += identity_service_files sources += session_v1_files sources += session_v2_files @@ -382,6 +374,7 @@ ohos_unittest("device_auth_identity_service_test") { "DEV_AUTH_FUNC_TEST", "ENABLE_PSEUDONYM", "DEV_AUTH_HIVIEW_ENABLE", + "DEV_AUTH_IS_ENABLE", "DEV_AUTH_PERMISSION_ENABLE", ] @@ -447,7 +440,6 @@ ohos_unittest("device_auth_interface_test") { sources += dev_frameworks_files sources += deviceauth_common_files sources += group_database_manager_files - sources += cred_database_manager_files sources += ext_plugin_manager_files sources += session_manager_files sources += session_v1_files @@ -574,11 +566,8 @@ ohos_unittest("deviceauth_unit_test") { sources += dev_frameworks_files sources += deviceauth_common_files sources += group_database_manager_files - sources += cred_database_manager_files sources += ext_plugin_manager_files sources += session_manager_files - sources += identity_service_files - sources += cred_listener_files sources += session_v1_files sources += session_v2_files sources += iso_protocol_files diff --git a/test/unittest/tdd_framework/unit_test/services/session_manager/session/v2/expand_sub_session/expand_process_lib/BUILD.gn b/test/unittest/tdd_framework/unit_test/services/session_manager/session/v2/expand_sub_session/expand_process_lib/BUILD.gn index 0cb4d6366dcff6cd5e787e91e544b44db5af5532..00da31c556a85ab921589285c49c2b92b95321d7 100644 --- a/test/unittest/tdd_framework/unit_test/services/session_manager/session/v2/expand_sub_session/expand_process_lib/BUILD.gn +++ b/test/unittest/tdd_framework/unit_test/services/session_manager/session/v2/expand_sub_session/expand_process_lib/BUILD.gn @@ -208,7 +208,6 @@ ohos_unittest("save_trusted_info_test") { sources += account_auth_plugin_mock_files sources += account_task_manager_mock_files sources += group_database_manager_files - sources += cred_database_manager_files sources += save_trusted_info_files sources += privacy_enhancement_mock_files sources += mk_agree_mock_files