diff --git a/oem_property/ohos/common/dslm_ohos_request.c b/oem_property/ohos/common/dslm_ohos_request.c index bc191afc4f40803f0b2a8ca6723418a2add34984..15947b92f336713b21caa467b73b2c2a4996f16b 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); @@ -214,21 +198,9 @@ int32_t GetCredFromCurrentDevice(char *credStr, uint32_t maxLen) } #endif -int32_t RequestOhosDslmCred(const DeviceIdentify *device, const RequestObject *obj, DslmCredBuff **credBuff) +static int32_t SelectDslmCredType(const DeviceIdentify *device, const RequestObject *obj, DslmCredBuff **credBuff, + char *credStr, int32_t credType) { - 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); @@ -236,9 +208,27 @@ int32_t RequestOhosDslmCred(const DeviceIdentify *device, const RequestObject *o 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; } +} - return SUCCESS; +int32_t RequestOhosDslmCred(const DeviceIdentify *device, const RequestObject *obj, DslmCredBuff **credBuff) +{ + SECURITY_LOG_INFO("start"); + 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; + } + + for (uint32_t i = 0; i < obj->arraySize; i++) { + ret = SelectDslmCredType(device, obj, credBuff, credStr, obj->credArray[i]); + if (ret == SUCCESS) { + return ret; + } + } + + SECURITY_LOG_ERROR("SelectDslmCredType failed"); + return ret; }