From 48ad3e2423b919dd63b7092b9f747c3698e5a760 Mon Sep 17 00:00:00 2001 From: zhuofan0129 <861080528@qq.com> Date: Wed, 13 Dec 2023 20:08:12 +0800 Subject: [PATCH] feat: add credType seeking Signed-off-by: zhuofan0129 <861080528@qq.com> --- oem_property/ohos/common/dslm_ohos_request.c | 51 ++++++++------------ 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/oem_property/ohos/common/dslm_ohos_request.c b/oem_property/ohos/common/dslm_ohos_request.c index bc191af..105c70a 100644 --- a/oem_property/ohos/common/dslm_ohos_request.c +++ b/oem_property/ohos/common/dslm_ohos_request.c @@ -100,22 +100,6 @@ static int32_t GenerateDslmCertChain(const DeviceIdentify *device, const Request return ret; } -static int32_t SelectDslmCredType(const DeviceIdentify *device, const RequestObject *obj, uint32_t *type) -{ - (void)device; - (void)obj; - if (HksAttestIsReadyAdapter() != SUCCESS) { -#ifdef L0_MINI - *type = CRED_TYPE_MINI; -#else - *type = CRED_TYPE_SMALL; -#endif - } else { - *type = CRED_TYPE_STANDARD; - } - return SUCCESS; -} - static int32_t RequestLiteDslmCred(uint32_t credType, uint8_t *data, uint32_t dataLen, DslmCredBuff **credBuff) { DslmCredBuff *out = CreateDslmCred(credType, dataLen, data); @@ -217,28 +201,31 @@ int32_t GetCredFromCurrentDevice(char *credStr, uint32_t maxLen) int32_t RequestOhosDslmCred(const DeviceIdentify *device, const RequestObject *obj, DslmCredBuff **credBuff) { SECURITY_LOG_INFO("start"); - uint32_t credType = 0; char credStr[DSLM_CRED_STR_LEN_MAX] = {0}; int32_t ret = GetCredFromCurrentDevice(credStr, DSLM_CRED_STR_LEN_MAX); if (ret != SUCCESS) { SECURITY_LOG_ERROR("read cred data from file failed"); return ret; } - ret = SelectDslmCredType(device, obj, &credType); - if (ret != SUCCESS) { - SECURITY_LOG_ERROR("SelectDslmCredType failed"); - return ret; - } - switch (credType) { - case CRED_TYPE_STANDARD: - return RequestStandardDslmCred(device, obj, credStr, credBuff); - case CRED_TYPE_SMALL: - case CRED_TYPE_MINI: - return RequestLiteDslmCred(credType, (uint8_t *)credStr, strlen(credStr) + 1, credBuff); - default: - SECURITY_LOG_ERROR("invalid cred type"); - return ERR_INVALID_PARA; + + for (uint32_t i = 0; i < obj->arraySize; i++) { + switch (obj->credArray[i]) { + case CRED_TYPE_STANDARD: + ret = RequestStandardDslmCred(device, obj, credStr, credBuff); + break; + case CRED_TYPE_SMALL: + case CRED_TYPE_MINI: + ret = RequestLiteDslmCred(obj->credArray[i], (uint8_t *)credStr, strlen(credStr) + 1, credBuff); + break; + default: + ret = ERR_INVALID_PARA; + break; + } + if (ret == SUCCESS) { + return ret; + } } - return SUCCESS; + SECURITY_LOG_ERROR("invalid cred type"); + return ERR_INVALID_PARA; } -- Gitee