mirror of
https://github.com/openharmony/xts_device_attest_lite.git
synced 2026-06-30 21:57:55 -04:00
@@ -17,6 +17,7 @@ devattest_innerkit_path = "${devattest_path}/interfaces/innerkits"
|
||||
|
||||
attest_core_path = "${devattest_path}/services/core"
|
||||
|
||||
devattest_unittest_module_path = "device_attest/device_attest"
|
||||
declare_args() {
|
||||
attest_release = "attest_release"
|
||||
attest_debug = "attest_debug"
|
||||
@@ -27,10 +28,10 @@ declare_args() {
|
||||
attest_build_target = attest_release
|
||||
|
||||
# using mock network authentication data
|
||||
enable_attest_mock_network = false
|
||||
enable_attest_test_mock_network = false
|
||||
|
||||
# using mock setting device data
|
||||
enable_attest_mock_device = false
|
||||
enable_attest_test_mock_device = false
|
||||
|
||||
# check for memory leaks
|
||||
enable_attest_debug_memory_leak = false
|
||||
@@ -43,6 +44,12 @@ declare_args() {
|
||||
|
||||
# 集成轻量设备授权验证模块
|
||||
integrate_attest_mini_module = true
|
||||
|
||||
# 域名增强关闭
|
||||
disable_attest_active_site = false
|
||||
|
||||
# token预置方案
|
||||
enable_attest_preset_token = false
|
||||
}
|
||||
|
||||
declare_args() {
|
||||
|
||||
@@ -23,7 +23,16 @@ extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define SOFTWARE_RESULT_DETAIL_SIZE 5
|
||||
#define SOFTWARE_RESULT_DETAIL_SIZE 5
|
||||
#define MAX_ATTEST_RESULT_SIZE (SOFTWARE_RESULT_DETAIL_SIZE + 2)
|
||||
|
||||
typedef enum {
|
||||
SOFTWARE_RESULT_VERSIONID,
|
||||
SOFTWARE_RESULT_PATCHLEVEL,
|
||||
SOFTWARE_RESULT_ROOTHASH,
|
||||
SOFTWARE_RESULT_PCID,
|
||||
SOFTWARE_RESULT_RESERVE,
|
||||
} SOFTWARE_RESULT_DETAIL_TYPE;
|
||||
|
||||
typedef struct {
|
||||
int32_t authResult;
|
||||
|
||||
@@ -15,10 +15,6 @@ import("//build/lite/config/component/lite_component.gni")
|
||||
import("//test/xts/device_attest_lite/build/devattestconfig.gni")
|
||||
import("attestsource.gni")
|
||||
|
||||
if (enable_attest_mock_network && enable_attest_mock_device) {
|
||||
sources_common += [ "${devattest_path}/test/unittest/src/attest_mock.c" ]
|
||||
}
|
||||
|
||||
if (enable_attest_debug_memory_leak) {
|
||||
sources_common += [ "utils/attest_utils_memleak.c" ]
|
||||
}
|
||||
@@ -37,11 +33,11 @@ config("devattest_core_config") {
|
||||
defines += [ "__ATTEST_HILOG_LEVEL_DEBUG__" ]
|
||||
}
|
||||
|
||||
if (enable_attest_mock_network) {
|
||||
if (enable_attest_test_mock_network) {
|
||||
defines += [ "__ATTEST_MOCK_NETWORK_STUB__" ]
|
||||
}
|
||||
|
||||
if (enable_attest_mock_device) {
|
||||
if (enable_attest_test_mock_device) {
|
||||
defines += [ "__ATTEST_MOCK_DEVICE_STUB__" ]
|
||||
}
|
||||
|
||||
@@ -52,6 +48,11 @@ config("devattest_core_config") {
|
||||
if (enable_attest_debug_dfx) {
|
||||
defines += [ "__ATTEST_DEBUG_DFX__" ]
|
||||
}
|
||||
|
||||
if (disable_attest_active_site) {
|
||||
defines += [ "__ATTEST_DISABLE_SITE__" ]
|
||||
}
|
||||
|
||||
defines += [ "MBEDTLS_ALLOW_PRIVATE_ACCESS" ]
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,17 @@
|
||||
// 是否存在重置标记
|
||||
bool AttestIsResetFlagExist(void)
|
||||
{
|
||||
return OEMIsFlagExist(OEM_FLAG_RESET);
|
||||
bool isExist = OEMIsFlagExist(OEM_FLAG_RESET);
|
||||
if (!isExist) {
|
||||
return false;
|
||||
}
|
||||
#if !defined(__ATTEST_ENABLE_PRESET_TOKEN__)
|
||||
TokenInfo tokenInfo;
|
||||
if (AttestReadToken(&tokenInfo) == TOKEN_UNPRESET) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
// 创建重置标记
|
||||
|
||||
@@ -75,10 +75,16 @@ int32_t AttestWriteToken(TokenInfo* tokenInfo)
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
int32_t ret = 0;
|
||||
unsigned int len = 0;
|
||||
#ifdef __LITEOS_M__
|
||||
len = TOKEN_ENCRYPT_LEN;
|
||||
#else
|
||||
len = sizeof(token);
|
||||
#endif
|
||||
if (ATTEST_MOCK_DEVICE_STUB_FLAG) {
|
||||
ret = OsWriteTokenStub(token, sizeof(token));
|
||||
ret = OsWriteTokenStub(token, len);
|
||||
} else {
|
||||
ret = HalWriteToken(token, sizeof(token));
|
||||
ret = HalWriteToken(token, len);
|
||||
}
|
||||
|
||||
if (ret != ATTEST_OK) {
|
||||
@@ -96,10 +102,16 @@ int32_t AttestReadToken(TokenInfo* tokenInfo)
|
||||
}
|
||||
char token[TOKEN_ENCRYPT_LEN + 1] = {0};
|
||||
int32_t ret = 0;
|
||||
unsigned int len = 0;
|
||||
#ifdef __LITEOS_M__
|
||||
len = TOKEN_ENCRYPT_LEN;
|
||||
#else
|
||||
len = sizeof(token);
|
||||
#endif
|
||||
if (ATTEST_MOCK_DEVICE_STUB_FLAG) {
|
||||
ret = OsReadTokenStub(token, sizeof(token));
|
||||
ret = OsReadTokenStub(token, len);
|
||||
} else {
|
||||
ret = HalReadToken(token, sizeof(token));
|
||||
ret = HalReadToken(token, len);
|
||||
}
|
||||
|
||||
if (ret != ATTEST_OK) {
|
||||
|
||||
@@ -138,6 +138,11 @@ char* OsGetSecurityPatchTagStub(void)
|
||||
return GetDeviceParaStub("securityPatchTag");
|
||||
}
|
||||
|
||||
char* OsGetSerialStub(void)
|
||||
{
|
||||
return GetDeviceParaStub("serial");
|
||||
}
|
||||
|
||||
static int32_t OsGetUnencryptedUdidStub(char **outputBuff, int32_t *outputSize)
|
||||
{
|
||||
char* manufacture = NULL;
|
||||
@@ -175,7 +180,7 @@ static int32_t OsGetUnencryptedUdidStub(char **outputBuff, int32_t *outputSize)
|
||||
ret = ATTEST_ERR;
|
||||
break;
|
||||
}
|
||||
ATTEST_LOG_INFO_ANONY("[OsGetUnencryptedUdidStub] udid = %s", udid);
|
||||
ATTEST_LOG_INFO("[OsGetUnencryptedUdidStub] udid = %s", udid);
|
||||
} while (0);
|
||||
ATTEST_MEM_FREE(manufacture);
|
||||
ATTEST_MEM_FREE(model);
|
||||
@@ -191,6 +196,10 @@ static int32_t OsGetUnencryptedUdidStub(char **outputBuff, int32_t *outputSize)
|
||||
|
||||
char* OsGetUdidStub(void)
|
||||
{
|
||||
char *udidStub = GetDeviceParaStub("udid");
|
||||
if (udidStub != NULL) {
|
||||
return udidStub;
|
||||
}
|
||||
char *udid = NULL;
|
||||
char *udidSha256 = NULL;
|
||||
int32_t udidSize = 0;
|
||||
@@ -208,13 +217,16 @@ char* OsGetUdidStub(void)
|
||||
ret = ATTEST_ERR;
|
||||
break;
|
||||
}
|
||||
|
||||
ret = Sha256Value((const unsigned char *)udid, udidSize, udidSha256, UDID_STRING_LEN + 1);
|
||||
ret = Sha256Value((const unsigned char *)udid, udidSize - 1, udidSha256, UDID_STRING_LEN + 1);
|
||||
if (ret != ATTEST_OK) {
|
||||
ATTEST_LOG_ERROR("[OsGetUdidStub] failed to Sha256");
|
||||
ATTEST_MEM_FREE(udidSha256);
|
||||
break;
|
||||
}
|
||||
ret = ToLowerStr(udidSha256, UDID_STRING_LEN + 1);
|
||||
if (ret != ATTEST_OK) {
|
||||
break;
|
||||
}
|
||||
} while (0);
|
||||
ATTEST_MEM_FREE(udid);
|
||||
if (ret != ATTEST_OK) {
|
||||
@@ -222,7 +234,7 @@ char* OsGetUdidStub(void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ATTEST_LOG_INFO_ANONY("[OsGetUdidStub] Sha256(udid) = %s\n", udidSha256);
|
||||
ATTEST_LOG_INFO("[OsGetUdidStub] Sha256(udid) = %s\n", udidSha256);
|
||||
return udidSha256;
|
||||
}
|
||||
|
||||
@@ -231,17 +243,13 @@ int OsGetAcKeyStub(char *acKey, unsigned int len)
|
||||
if ((acKey == NULL) || (len == 0)) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
const char manufacturekeyBuf[] = {
|
||||
0x13, 0x42, 0x3F, 0x3F, 0x53, 0x3F, 0x72, 0x30, 0x3F, 0x3F, 0x1C, 0x3F, 0x2F, 0x3F, 0x2E, 0x42,
|
||||
0x3F, 0x08, 0x3F, 0x57, 0x3F, 0x10, 0x3F, 0x3F, 0x29, 0x17, 0x52, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
|
||||
0x57, 0x16, 0x3F, 0x7D, 0x4A, 0x0F, 0x3F, 0x3F, 0x3F, 0x30, 0x0C, 0x3F, 0x3F, 0x4C, 0x3F, 0x47
|
||||
};
|
||||
uint32_t manufacturekeyBufLen = sizeof(manufacturekeyBuf);
|
||||
if (len < manufacturekeyBufLen) {
|
||||
|
||||
char *manufacturekeyBuf = GetDeviceParaStub("manuKey");
|
||||
if (manufacturekeyBuf == NULL) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
int ret = memcpy_s(acKey, len, manufacturekeyBuf, manufacturekeyBufLen);
|
||||
int ret = HEXStringToAscii(manufacturekeyBuf, strlen(manufacturekeyBuf), acKey, len);
|
||||
ATTEST_MEM_FREE(manufacturekeyBuf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -250,13 +258,18 @@ int OsGetProdIdStub(char* productId, uint32_t len)
|
||||
if ((productId == NULL) || (len == 0)) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
const char productIdBuf[] = "OH00000D";
|
||||
char *productIdBuf = GetDeviceParaStub("productId");
|
||||
if (productIdBuf == NULL) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
uint32_t productIdLen = strlen(productIdBuf);
|
||||
if (len < productIdLen) {
|
||||
ATTEST_MEM_FREE(productIdBuf);
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
int ret = memcpy_s(productId, len, productIdBuf, productIdLen);
|
||||
ATTEST_MEM_FREE(productIdBuf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -265,13 +278,19 @@ int OsGetProdKeyStub(char* productKey, uint32_t len)
|
||||
if ((productKey == NULL) || (len == 0)) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
const char productKeyBuf[] = "test";
|
||||
uint32_t productKeyLen = sizeof(productKeyBuf);
|
||||
|
||||
char *productKeyBuf = GetDeviceParaStub("productKey");
|
||||
if (productKeyBuf == NULL) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
uint32_t productKeyLen = strlen(productKeyBuf);
|
||||
if (len < productKeyLen) {
|
||||
ATTEST_MEM_FREE(productKeyBuf);
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
int ret = memcpy_s(productKey, len, productKeyBuf, productKeyLen);
|
||||
ATTEST_MEM_FREE(productKeyBuf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -281,8 +300,9 @@ int32_t OsReadTokenStub(char* buffer, uint32_t bufferLen)
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
int32_t ret = ReadFile(ATTEST_MOCK_STUB_PATH, ATTEST_MOCK_TOKEN_FILE_NAME, buffer, bufferLen);
|
||||
if (ret != 0) {
|
||||
return ATTEST_ERR;
|
||||
if (ret != ATTEST_OK) {
|
||||
// token file does not exist, shuold return TOKEN_UNPRESET
|
||||
return TOKEN_UNPRESET;
|
||||
}
|
||||
return ATTEST_OK;
|
||||
}
|
||||
|
||||
@@ -122,5 +122,8 @@ int32_t OEMWriteAuthResultCode(const char* data, uint32_t len)
|
||||
// 读取认证结果
|
||||
int32_t OEMReadAuthResultCode(char* buffer, uint32_t bufferLen)
|
||||
{
|
||||
if (!IsFileExist(AUTH_RESULT_PATH, AUTH_RESULT_CODE_FILE_NAME)) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
return ReadFile(AUTH_RESULT_PATH, AUTH_RESULT_CODE_FILE_NAME, buffer, bufferLen);
|
||||
}
|
||||
|
||||
@@ -82,5 +82,8 @@ char* AttestGetUdid(void)
|
||||
|
||||
char* AttestGetSerial(void)
|
||||
{
|
||||
if (ATTEST_MOCK_DEVICE_STUB_FLAG) {
|
||||
return OsGetSerialStub();
|
||||
}
|
||||
return OsGetSerial();
|
||||
}
|
||||
|
||||
@@ -303,7 +303,7 @@ static int32_t ProcAttestImpl(void)
|
||||
DestroySysData();
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
// 检查本地数据是否修改或过期,进行重新认证
|
||||
// 检查本地数据是否修改或过期,进行重新验证
|
||||
if (!IsAuthStatusChg()) {
|
||||
ATTEST_LOG_WARN("[ProcAttestImpl] There is no change on auth status.");
|
||||
UpdateAuthResultCode(AUTH_SUCCESS);
|
||||
@@ -316,6 +316,7 @@ static int32_t ProcAttestImpl(void)
|
||||
DestroySysData();
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
// 走授权验证流程
|
||||
ret = AttestStartup(authResult);
|
||||
DestroySysData();
|
||||
DestroyAuthResult(&authResult);
|
||||
@@ -327,11 +328,11 @@ int32_t ProcAttest(void)
|
||||
pthread_mutex_lock(&g_mtxAttest);
|
||||
PrintCurrentTime();
|
||||
int32_t ret;
|
||||
int32_t retValue;
|
||||
if (ATTEST_DEBUG_MEMORY_LEAK) {
|
||||
ret = InitMemNodeList();
|
||||
ATTEST_LOG_INFO("[ProcAttest] Init mem node list, ret = %d.", ret);
|
||||
retValue = InitMemNodeList();
|
||||
ATTEST_LOG_INFO("[ProcAttest] Init mem node list, retValue = %d.", retValue);
|
||||
}
|
||||
|
||||
do {
|
||||
// init network server info
|
||||
ret = InitNetworkServerInfo();
|
||||
@@ -345,18 +346,17 @@ int32_t ProcAttest(void)
|
||||
ATTEST_LOG_ERROR("[ProcAttest] Connect wise device failed, ret = %d.", ret);
|
||||
break;
|
||||
}
|
||||
|
||||
// 主流程
|
||||
ret = ProcAttestImpl();
|
||||
if (ret != ATTEST_OK) {
|
||||
ATTEST_LOG_ERROR("[ProcAttest] Proc Attest failed, ret = %d.", ret);
|
||||
}
|
||||
DisConnectWiseDevice();
|
||||
} while (0);
|
||||
|
||||
if (ATTEST_DEBUG_MEMORY_LEAK) {
|
||||
PrintMemNodeList();
|
||||
ret = DestroyMemNodeList();
|
||||
ATTEST_LOG_INFO("[ProcAttest] Destroy mem node list, ret = %d.", ret);
|
||||
retValue = DestroyMemNodeList();
|
||||
ATTEST_LOG_INFO("[ProcAttest] Destroy mem node list, retValue = %d.", retValue);
|
||||
}
|
||||
PrintCurrentTime();
|
||||
pthread_mutex_unlock(&g_mtxAttest);
|
||||
|
||||
@@ -48,9 +48,9 @@ int32_t GenActiveMsg(AuthResult* authResult, const ChallengeResult* challengeRes
|
||||
// 获取tokenId和tokenValue(hdmac加密)
|
||||
uint8_t tokenId[TOKEN_ID_LEN + 1] = {0};
|
||||
uint8_t tokenValueHmac[TOKEN_VALUE_HMAC_LEN + 1] = {0};
|
||||
if (GetTokenValueHmac((const char*)(challengeResult->challenge), tokenValueHmac, TOKEN_VALUE_HMAC_LEN) != 0 ||
|
||||
GetTokenId(tokenId, TOKEN_ID_LEN) != 0) {
|
||||
ATTEST_LOG_ERROR("[GenActiveMsg] Get tokenId or tokenValue failed.");
|
||||
int32_t ret = GetTokenValueAndId(challengeResult->challenge, tokenValueHmac, TOKEN_VALUE_HMAC_LEN,\
|
||||
tokenId, TOKEN_ID_LEN);
|
||||
if (ret != ATTEST_OK) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ int32_t ParseActiveResult(const char* jsonStr)
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
if ((int32_t)errorCode != ATTEST_OK) {
|
||||
ATTEST_LOG_ERROR("[ParseActiveResult] -errorCode = %d.", -(int32_t)(errorCode));
|
||||
ATTEST_LOG_ERROR("[ParseActiveResult] errorCode = %d.", -(int32_t)(errorCode));
|
||||
return -(int32_t)((errorCode));
|
||||
}
|
||||
return ATTEST_OK;
|
||||
|
||||
@@ -36,7 +36,7 @@ bool IsAuthStatusChg(void)
|
||||
ATTEST_LOG_DEBUG("[IsAuthStatusChg] Begin.");
|
||||
char* authStatusBase64 = NULL;
|
||||
if (GetAuthStatus(&authStatusBase64) != ATTEST_OK) {
|
||||
ATTEST_LOG_ERROR("[IsAuthStatusChg] Load auth status failed or status file not exist");
|
||||
ATTEST_LOG_WARN("[IsAuthStatusChg] Load auth status failed or status file not exist");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -121,11 +121,15 @@ int32_t GetAttestStatusPara(void)
|
||||
char attestResult[AUTH_RESULT_LEN] = {0};
|
||||
int ret = AttestGetParameter(STARTSUP_PARA_ATTEST_KEY, STARTSUP_PARA_ATTEST_ERROR,
|
||||
attestResult, sizeof(attestResult));
|
||||
if ((ret != 0) && (strcmp(STARTSUP_PARA_ATTEST_OK, attestResult) == 0)) {
|
||||
if (ret == 0) {
|
||||
ATTEST_LOG_ERROR("[GetAttestStatusPara] failed to get parameter.");
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
if (strcmp(STARTSUP_PARA_ATTEST_OK, attestResult) == 0) {
|
||||
ATTEST_LOG_INFO("[GetAttestStatusPara] success, persist.xts.devattest.authresult = %s", attestResult);
|
||||
return ATTEST_OK;
|
||||
}
|
||||
ATTEST_LOG_WARN("[GetAttestStatusPara] failed.");
|
||||
ATTEST_LOG_WARN("[GetAttestStatusPara] failed, persist.xts.devattest.authresult = ", attestResult);
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
@@ -856,9 +860,9 @@ int32_t GenAuthMsg(const ChallengeResult* challengeResult, DevicePacket** devPac
|
||||
|
||||
uint8_t tokenValueHmac[TOKEN_VALUE_HMAC_LEN + 1] = {0};
|
||||
uint8_t tokenId[TOKEN_ID_LEN + 1] = {0};
|
||||
if (GetTokenValueHmac(challengeResult->challenge, tokenValueHmac, TOKEN_VALUE_HMAC_LEN) != 0 ||
|
||||
GetTokenId(tokenId, TOKEN_ID_LEN) != 0) {
|
||||
ATTEST_LOG_ERROR("[GenAuthMsg] Get TokenId or TokenValueHmac failed");
|
||||
int32_t ret = GetTokenValueAndId(challengeResult->challenge, tokenValueHmac, TOKEN_VALUE_HMAC_LEN,\
|
||||
tokenId, TOKEN_ID_LEN);
|
||||
if (ret != ATTEST_OK) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
@@ -874,7 +878,7 @@ int32_t GenAuthMsg(const ChallengeResult* challengeResult, DevicePacket** devPac
|
||||
devicePacket->tokenInfo.uuid = AttestStrdup((char*)tokenId);
|
||||
devicePacket->tokenInfo.token = AttestStrdup((char*)tokenValueHmac);
|
||||
devicePacket->pcid = StrdupDevInfo(PCID);
|
||||
int32_t ret = PackProductInfo(&devicePacket->productInfo);
|
||||
ret = PackProductInfo(&devicePacket->productInfo);
|
||||
if (ret != ATTEST_OK) {
|
||||
ATTEST_LOG_ERROR("[GenAuthMsg] Pack ProductInfo failed.");
|
||||
FREE_DEVICE_PACKET(devicePacket);
|
||||
|
||||
@@ -96,7 +96,7 @@ static int32_t ParseChallengeResult(const char* jsonStr, ChallengeResult* challe
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
if ((int32_t)errorCode != ATTEST_OK) {
|
||||
ATTEST_LOG_ERROR("[ParseChallengeResult] -errorCode = %d.", -(int32_t)(errorCode));
|
||||
ATTEST_LOG_ERROR("[ParseChallengeResult] errorCode = %d.", -(int32_t)(errorCode));
|
||||
return -(int32_t)(errorCode);
|
||||
}
|
||||
|
||||
@@ -110,6 +110,7 @@ static int32_t ParseChallengeResult(const char* jsonStr, ChallengeResult* challe
|
||||
ATTEST_LOG_ERROR("[ParseChallengeResult] GetObjectItem challenge failed.");
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
#ifndef __ATTEST_DISABLE_SITE__
|
||||
char* serverInfo = NULL;
|
||||
do {
|
||||
ret = GetObjectItemValueObject(jsonStr, "serverInfo", &serverInfo);
|
||||
@@ -129,6 +130,7 @@ static int32_t ParseChallengeResult(const char* jsonStr, ChallengeResult* challe
|
||||
}
|
||||
} while (0);
|
||||
ATTEST_MEM_FREE(serverInfo);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "attest_service_device.h"
|
||||
|
||||
char* g_devSysInfos[SYS_DEV_MAX] = {NULL};
|
||||
const char* g_devSysInfosStr[] = {
|
||||
const char* g_devSysInfosStr[SYS_DEV_MAX] = {
|
||||
"VERSION_ID",
|
||||
"ROOT_HASH",
|
||||
"DISPLAY_VERSION",
|
||||
@@ -36,7 +36,7 @@ const char* g_devSysInfosStr[] = {
|
||||
"PCID",
|
||||
};
|
||||
|
||||
SetDataFunc g_setDataFunc[] = {
|
||||
SetDataFunc g_setDataFunc[SYS_DEV_MAX] = {
|
||||
&AttestGetVersionId,
|
||||
&AttestGetBuildRootHash,
|
||||
&AttestGetDisplayVersion,
|
||||
@@ -51,6 +51,35 @@ SetDataFunc g_setDataFunc[] = {
|
||||
&GetPcid,
|
||||
};
|
||||
|
||||
size_t g_devSysInfosMaxLen[SYS_DEV_MAX] = {
|
||||
MAX_ATTEST_VERSION_ID_LEN,
|
||||
MAX_ATTEST_DEFAULT_LEN,
|
||||
MAX_ATTEST_DISPLAY_VERSION_LEN,
|
||||
MAX_ATTEST_MANUFACTURE_LEN,
|
||||
MAX_ATTEST_MODEL_LEN,
|
||||
MAX_ATTEST_BRAND_LEN,
|
||||
MAX_ATTEST_PATCH_LEN,
|
||||
MAX_ATTEST_DEFAULT_LEN,
|
||||
MAX_ATTEST_DEFAULT_LEN,
|
||||
MAX_ATTEST_DEFAULT_LEN,
|
||||
MAX_ATTEST_DEFAULT_LEN,
|
||||
MAX_ATTEST_DEFAULT_LEN,
|
||||
};
|
||||
|
||||
/* 根据PCS表检查长度 */
|
||||
static int32_t CheckSysInfosLength(SYS_DEV_TYPE_E type, size_t sysInfosLength)
|
||||
{
|
||||
if (type == ROOT_HASH || type == UDID || type == RANDOM_UUID ||\
|
||||
type == APP_ID || type == TENANT_ID || type == PCID) {
|
||||
return ATTEST_OK;
|
||||
}
|
||||
if (sysInfosLength > g_devSysInfosMaxLen[type]) {
|
||||
ATTEST_LOG_ERROR("[CheckSysInfosLength] The length of sysInfo type %d exceeds limit", type);
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
return ATTEST_OK;
|
||||
}
|
||||
|
||||
static int32_t SetSysData(SYS_DEV_TYPE_E type)
|
||||
{
|
||||
if (type >= SYS_DEV_MAX) {
|
||||
@@ -58,13 +87,17 @@ static int32_t SetSysData(SYS_DEV_TYPE_E type)
|
||||
}
|
||||
SetDataFunc setDataFunc = g_setDataFunc[type];
|
||||
if (setDataFunc == NULL) {
|
||||
ATTEST_LOG_ERROR("[SetSysData] g_setDataFunc failed");
|
||||
ATTEST_LOG_ERROR("[SetSysData] g_setDataFunc failed, type = %d", type);
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
char* value = setDataFunc();
|
||||
if (value == NULL) {
|
||||
ATTEST_LOG_ERROR("[SetSysData] set Data failed");
|
||||
ATTEST_LOG_ERROR("[SetSysData] set Data failed, type = %d", type);
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
if (CheckSysInfosLength(type, strlen(value)) != ATTEST_OK) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
@@ -100,7 +133,7 @@ static void PrintDevSysInfo(void)
|
||||
|
||||
static void VerifyUDID(void)
|
||||
{
|
||||
char *udidSrc = AttestGetUdid();
|
||||
char *udidSrc = g_devSysInfos[UDID];
|
||||
if (udidSrc == NULL) {
|
||||
ATTEST_LOG_ERROR("[VerifyUDID] Failed to get udidSrc");
|
||||
return;
|
||||
@@ -108,14 +141,12 @@ static void VerifyUDID(void)
|
||||
char *udidDest = (char *)GetUdidForVerification();
|
||||
if (udidDest == NULL) {
|
||||
ATTEST_LOG_ERROR("[VerifyUDID] Failed to get udidDest");
|
||||
ATTEST_MEM_FREE(udidSrc);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(udidSrc, udidDest) != 0) {
|
||||
ATTEST_LOG_ERROR("[VerifyUDID] udid is invalid");
|
||||
}
|
||||
ATTEST_MEM_FREE(udidSrc);
|
||||
ATTEST_MEM_FREE(udidDest);
|
||||
return;
|
||||
}
|
||||
@@ -143,14 +174,13 @@ int32_t InitSysData(void)
|
||||
|
||||
void DestroySysData(void)
|
||||
{
|
||||
if (IsSysDataEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < SYS_DEV_MAX; i++) {
|
||||
(void)memset_s(g_devSysInfos[i], strlen(g_devSysInfos[i]), 0, strlen(g_devSysInfos[i]));
|
||||
ATTEST_MEM_FREE(g_devSysInfos[i]);
|
||||
if (g_devSysInfos[i] != NULL) {
|
||||
(void)memset_s(g_devSysInfos[i], strlen(g_devSysInfos[i]), 0, strlen(g_devSysInfos[i]));
|
||||
ATTEST_MEM_FREE(g_devSysInfos[i]);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// StrdupDevInfo 涉及申请内存,需要外部释放
|
||||
@@ -208,11 +238,11 @@ char* GetRandomUuid(void)
|
||||
}
|
||||
static unsigned char* GetUdidDecrypted(void)
|
||||
{
|
||||
char *enShortName = AttestGetManufacture();
|
||||
char *enShortName = StrdupDevInfo(MANU_FACTURE);
|
||||
if (enShortName == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
char *model = AttestGetProductModel();
|
||||
char *model = StrdupDevInfo(PRODUCT_MODEL);
|
||||
if (model == NULL) {
|
||||
ATTEST_MEM_FREE(enShortName);
|
||||
return NULL;
|
||||
@@ -229,9 +259,7 @@ static unsigned char* GetUdidDecrypted(void)
|
||||
unsigned char *udid = NULL;
|
||||
int32_t ret = ATTEST_ERR;
|
||||
do {
|
||||
if ((strlen(enShortName) > MAX_ATTEST_MANUFACTURE_LEN) || \
|
||||
(strlen(model) > MAX_ATTEST_MODEL_LEN) || \
|
||||
(strlen(sn) > MAX_ATTEST_SERIAL_LEN)) {
|
||||
if (strlen(sn) > MAX_ATTEST_SERIAL_LEN) {
|
||||
break;
|
||||
}
|
||||
int32_t udidSize = enShortNameLen + modelLen + snLen + 1;
|
||||
|
||||
@@ -36,12 +36,12 @@ int32_t GenResetMsg(ChallengeResult* challengeResult, DevicePacket** devPacket)
|
||||
|
||||
uint8_t tokenId[TOKEN_ID_LEN + 1] = {0};
|
||||
uint8_t tokenValueHmac[TOKEN_VALUE_HMAC_LEN + 1] = {0};
|
||||
if (GetTokenValueHmac(challengeResult->challenge, tokenValueHmac, TOKEN_VALUE_HMAC_LEN) != ATTEST_OK ||
|
||||
GetTokenId(tokenId, TOKEN_ID_LEN) != ATTEST_OK) {
|
||||
ATTEST_LOG_ERROR("[GenResetMsg] Get device token failed.");
|
||||
int32_t ret = GetTokenValueAndId(challengeResult->challenge, tokenValueHmac, TOKEN_VALUE_HMAC_LEN,\
|
||||
tokenId, TOKEN_ID_LEN);
|
||||
if (ret != ATTEST_OK) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
|
||||
DevicePacket* devicePacket = CreateDevicePacket();
|
||||
if (devicePacket == NULL) {
|
||||
ATTEST_LOG_ERROR("[GenResetMsg] Create DevicePacket failed.");
|
||||
@@ -94,7 +94,7 @@ int32_t ParseResetResult(const char* jsonStr)
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
if ((int32_t)errorCode != ATTEST_OK) {
|
||||
ATTEST_LOG_ERROR("[ParseResetResult] -errorCode = %d.", -(int32_t)errorCode);
|
||||
ATTEST_LOG_ERROR("[ParseResetResult] errorCode = %d.", -(int32_t)errorCode);
|
||||
return -(int32_t)(errorCode);
|
||||
}
|
||||
return ATTEST_OK;
|
||||
|
||||
@@ -85,6 +85,7 @@ static void AttestAuthCallBack(void *argv)
|
||||
int32_t AttestTask(void)
|
||||
{
|
||||
ATTEST_LOG_INFO("[AttestTask] Begin.");
|
||||
// 执行主流程代码
|
||||
int32_t ret = ProcAttest();
|
||||
if (ret != ATTEST_OK) {
|
||||
ATTEST_LOG_ERROR("[AttestTask] Proc failed ret = %d.", ret);
|
||||
|
||||
@@ -25,17 +25,6 @@ extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define SOFTWARE_RESULT_DETAIL_SIZE 5
|
||||
#define MAX_ATTEST_RESULT_SIZE (SOFTWARE_RESULT_DETAIL_SIZE + 2)
|
||||
|
||||
typedef enum {
|
||||
SOFTWARE_RESULT_VERSIONID,
|
||||
SOFTWARE_RESULT_PATCHLEVEL,
|
||||
SOFTWARE_RESULT_ROOTHASH,
|
||||
SOFTWARE_RESULT_PCID,
|
||||
SOFTWARE_RESULT_RESERVE,
|
||||
} SOFTWARE_RESULT_DETAIL_TYPE;
|
||||
|
||||
int32_t AttestTask(void);
|
||||
|
||||
int32_t EntryGetAttestStatus(AttestResultInfo* attestResultInfo);
|
||||
|
||||
@@ -67,6 +67,8 @@ char* OsGetBrandStub(void);
|
||||
|
||||
char* OsGetSecurityPatchTagStub(void);
|
||||
|
||||
char* OsGetSerialStub(void);
|
||||
|
||||
char* OsGetUdidStub(void);
|
||||
|
||||
int OsGetAcKeyStub(char *acKey, unsigned int len);
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#ifndef __ATTEST_SERVICE_ACTIVE_H__
|
||||
#define __ATTEST_SERVICE_ACTIVE_H__
|
||||
|
||||
#include "attest_type.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#define __ATTEST_SERVICE_AUTH_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "attest_type.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#ifndef __ATTEST_SERVICE_CHALLENGE_H__
|
||||
#define __ATTEST_SERVICE_CHALLENGE_H__
|
||||
|
||||
#include "attest_type.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -17,6 +17,16 @@
|
||||
#define __ATTEST_SERVICE_DEVICE_H__
|
||||
|
||||
#include "attest_type.h"
|
||||
// 最大长度限制
|
||||
#define MAX_ATTEST_DEFAULT_LEN 64
|
||||
|
||||
#define MAX_ATTEST_SERIAL_LEN 64
|
||||
#define MAX_ATTEST_VERSION_ID_LEN 255
|
||||
#define MAX_ATTEST_DISPLAY_VERSION_LEN 64
|
||||
#define MAX_ATTEST_MANUFACTURE_LEN 32
|
||||
#define MAX_ATTEST_MODEL_LEN 32
|
||||
#define MAX_ATTEST_BRAND_LEN 32
|
||||
#define MAX_ATTEST_PATCH_LEN 64
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#ifndef __ATTEST_SERVICE_RESET_H__
|
||||
#define __ATTEST_SERVICE_RESET_H__
|
||||
|
||||
#include "attest_type.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -67,6 +67,8 @@ extern "C" {
|
||||
#define MAX_ATTEST_MODEL_LEN 32
|
||||
#define MAX_ATTEST_SERIAL_LEN 64
|
||||
|
||||
#define SHA256_OUTPUT_SIZE 32
|
||||
|
||||
// 认证接口返回值,与json结构一一对应
|
||||
typedef struct {
|
||||
int32_t errorCode;
|
||||
|
||||
@@ -32,9 +32,8 @@ extern "C" {
|
||||
#define UUID_FORMAT_INDEX_3 16
|
||||
#define UUID_FORMAT_INDEX_4 20
|
||||
|
||||
int32_t GetTokenValueHmac(const char* challenge, uint8_t* tokenValueHmac, uint8_t tokenValueHmacLen);
|
||||
|
||||
int32_t GetTokenId(uint8_t* tokenId, uint8_t tokenIdLen);
|
||||
int32_t GetTokenValueAndId(const char* challenge, uint8_t* tokenValueHmac, uint8_t tokenValueHmacLen,\
|
||||
uint8_t* tokenId, uint8_t tokenIdLen);
|
||||
|
||||
int32_t FlushToken(AuthResult* authResult);
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
#define DEV_BUF_LENGTH 3
|
||||
#define HASH_LENGTH 32
|
||||
|
||||
#define ATTEST_EVEN_NUMBER 2
|
||||
|
||||
void AttestMemFree(void **point);
|
||||
|
||||
#define ATTEST_MEM_FREE(pointer) AttestMemFree((void **)&(pointer))
|
||||
@@ -51,10 +53,14 @@ void PrintCurrentTime(void);
|
||||
|
||||
int32_t ToLowerStr(char* str, int len);
|
||||
|
||||
int Sha256ValueToAscii(const unsigned char *src, int srcLen, unsigned char *dest, int destLen);
|
||||
|
||||
int Sha256Value(const unsigned char *src, int srcLen, char *dest, int destLen);
|
||||
|
||||
int32_t AnonymiseStr(char* str);
|
||||
|
||||
int32_t HEXStringToAscii(const char* input, int32_t inputLen, char* output, int32_t outputLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@ DevicePacket* CreateDevicePacket(void)
|
||||
devicePacket->productInfo.rootHash = NULL;
|
||||
devicePacket->productInfo.patchTag = NULL;
|
||||
devicePacket->kitinfo = NULL;
|
||||
devicePacket->pcid = NULL;
|
||||
return devicePacket;
|
||||
}
|
||||
|
||||
@@ -123,6 +124,7 @@ void DestroyDevicePacket(DevicePacket** devPacket)
|
||||
ATTEST_MEM_FREE(devicePacket->productInfo.rootHash);
|
||||
ATTEST_MEM_FREE(devicePacket->productInfo.patchTag);
|
||||
ATTEST_MEM_FREE(devicePacket->kitinfo);
|
||||
ATTEST_MEM_FREE(devicePacket->pcid);
|
||||
ATTEST_MEM_FREE(*devPacket);
|
||||
}
|
||||
|
||||
@@ -272,6 +274,7 @@ void D2CClose(void)
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef __ATTEST_DISABLE_SITE__
|
||||
static int32_t BuildCoapChallServerInfo(cJSON **postData)
|
||||
{
|
||||
if (postData == NULL) {
|
||||
@@ -311,6 +314,7 @@ static int32_t BuildCoapChallServerInfo(cJSON **postData)
|
||||
}
|
||||
return ATTEST_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
char* BuildCoapChallBody(const DevicePacket *postValue)
|
||||
{
|
||||
@@ -330,11 +334,14 @@ char* BuildCoapChallBody(const DevicePacket *postValue)
|
||||
ATTEST_LOG_ERROR("[BuildCoapChallBody] postData AddStringToObject fail");
|
||||
break;
|
||||
}
|
||||
#ifndef __ATTEST_DISABLE_SITE__
|
||||
ret = BuildCoapChallServerInfo(&postData);
|
||||
if (ret != ATTEST_OK) {
|
||||
ATTEST_LOG_ERROR("[BuildCoapChallBody] BuildCoapChallServerInfo fail");
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
ret = ATTEST_OK;
|
||||
} while (0);
|
||||
if (ret != ATTEST_OK) {
|
||||
cJSON_Delete(postData);
|
||||
@@ -1059,6 +1066,10 @@ static int32_t ParseNetworkInfosConfig(char *inputData, List *list)
|
||||
ret = ATTEST_ERR;
|
||||
break;
|
||||
}
|
||||
if (!cJSON_IsArray(array)) {
|
||||
ret = ATTEST_ERR;
|
||||
break;
|
||||
}
|
||||
int32_t arraySize = cJSON_GetArraySize(array);
|
||||
for (int32_t i = 0; i < arraySize; i++) {
|
||||
char *valueString = cJSON_GetStringValue(cJSON_GetArrayItem(array, i));
|
||||
|
||||
@@ -51,7 +51,7 @@ int32_t Base64Encode(const uint8_t* srcData, size_t srcDataLen, uint8_t* base64E
|
||||
int32_t ret = mbedtls_base64_encode(NULL, 0, &outLen, srcData, srcDataLen);
|
||||
|
||||
if ((outLen == 0) || (outLen > base64EncodeMaxLen)) {
|
||||
ATTEST_LOG_ERROR("[Base64Encode] Base64 encode get outLen failed, outLen = %u, ret = -0x00%x", outLen, -ret);
|
||||
ATTEST_LOG_ERROR("[Base64Encode] Base64 encode get outLen failed, outLen = %zu, ret = -0x00%x", outLen, -ret);
|
||||
return ERR_ATTEST_SECURITY_BASE64_ENCODE;
|
||||
}
|
||||
uint8_t base64Data[outLen];
|
||||
|
||||
@@ -60,12 +60,10 @@ int32_t WriteTicketToDevice(const char* ticket, uint8_t ticketLen)
|
||||
ATTEST_LOG_ERROR("[WriteTicketToDevice] ticket or salt memcpy_s fail.");
|
||||
return ERR_ATTEST_SECURITY_MEM_MEMCPY;
|
||||
}
|
||||
|
||||
if (AttestWriteTicket(&ticketInfo) != 0) {
|
||||
ATTEST_LOG_ERROR("[WriteTicketToDevice] Write ticket failed");
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
ATTEST_LOG_DEBUG("[WriteTicketToDevice] End.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <securec.h>
|
||||
#include "mbedtls/md.h"
|
||||
#include "mbedtls/hkdf.h"
|
||||
#include "attest_adapter.h"
|
||||
#include "attest_dfx.h"
|
||||
#include "attest_utils.h"
|
||||
@@ -49,6 +50,7 @@ static int32_t EncryptHmac(const char *challenge, const uint8_t *tokenValue, siz
|
||||
return ATTEST_OK;
|
||||
}
|
||||
|
||||
#if defined(__ATTEST_ENABLE_PRESET_TOKEN__)
|
||||
static uint8_t *GetIKM(void)
|
||||
{
|
||||
uint8_t *ikm = NULL;
|
||||
@@ -78,7 +80,6 @@ static uint8_t *GetIKM(void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
(void)memset_s(ikm, ikmSize, 0, ikmSize);
|
||||
if ((memcpy_s(ikm, ikmSize, productKey, productKeyLen) != 0) || \
|
||||
(memcpy_s(ikm + productKeyLen, ikmSize, productId, productIdLen) != 0)) {
|
||||
ATTEST_LOG_ERROR("[GetIKM] Failed to merge ikm");
|
||||
@@ -240,6 +241,202 @@ static int32_t GetTokenIdSpecial(uint8_t* tokenId, uint8_t tokenIdLen)
|
||||
|
||||
return ATTEST_OK;
|
||||
}
|
||||
#else
|
||||
/*Same as static int32_t SetSocketCliented(char* udid, char **outClientId)*/
|
||||
static int32_t GetProductSalt(unsigned char *salt, int32_t saltLen)
|
||||
{
|
||||
if (salt == NULL || saltLen < 0) {
|
||||
ATTEST_LOG_ERROR("[GetProductSalt] Invalid parameter");
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
char *udid = StrdupDevInfo(UDID);
|
||||
if (udid == NULL) {
|
||||
ATTEST_LOG_ERROR("[GetProductSalt] Failed to get udid");
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
if (ToLowerStr(udid, strlen(udid)) != ATTEST_OK) {
|
||||
ATTEST_MEM_FREE(udid);
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
int32_t ret = Sha256ValueToAscii((unsigned char *)udid, strlen(udid), salt, saltLen);
|
||||
ATTEST_MEM_FREE(udid);
|
||||
if (ret != ATTEST_OK) {
|
||||
ATTEST_LOG_ERROR("[GetProductSalt] failed to Sha256");
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
return ATTEST_OK;
|
||||
}
|
||||
|
||||
static uint8_t *GetProductIKMDecrypted(void)
|
||||
{
|
||||
char *enShortName = StrdupDevInfo(MANU_FACTURE);
|
||||
if (enShortName == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *brand = StrdupDevInfo(BRAND);
|
||||
if (brand == NULL) {
|
||||
ATTEST_MEM_FREE(enShortName);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *model = StrdupDevInfo(PRODUCT_MODEL);
|
||||
if (model == NULL) {
|
||||
ATTEST_MEM_FREE(enShortName);
|
||||
ATTEST_MEM_FREE(brand);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned char *ikm = NULL;
|
||||
int32_t ret = ATTEST_ERR;
|
||||
do {
|
||||
int32_t ikmSize = strlen(enShortName) + strlen(brand) + strlen(model) + 1;
|
||||
ikm = (unsigned char *)ATTEST_MEM_MALLOC(ikmSize);
|
||||
if (ikm == NULL) {
|
||||
ATTEST_LOG_ERROR("[GetProductIKMDecrypted] Failed to malloc ikm");
|
||||
break;
|
||||
}
|
||||
|
||||
if (strcat_s((char*)ikm, ikmSize, enShortName) != 0 ||
|
||||
strcat_s((char*)ikm, ikmSize, brand) != 0 ||
|
||||
strcat_s((char*)ikm, ikmSize, model) != 0) {
|
||||
ATTEST_LOG_ERROR("[GetProductIKMDecrypted] Failed to merge ikm");
|
||||
ATTEST_MEM_FREE(ikm);
|
||||
break;
|
||||
}
|
||||
|
||||
ret = ATTEST_OK;
|
||||
} while (0);
|
||||
ATTEST_MEM_FREE(enShortName);
|
||||
ATTEST_MEM_FREE(brand);
|
||||
ATTEST_MEM_FREE(model);
|
||||
if (ret != ATTEST_OK) {
|
||||
return NULL;
|
||||
}
|
||||
return ikm;
|
||||
}
|
||||
|
||||
static int32_t GetProductIKM(unsigned char *ikm, int32_t ikmLen)
|
||||
{
|
||||
unsigned char *ikmDecrypted = GetProductIKMDecrypted();
|
||||
if (ikmDecrypted == NULL) {
|
||||
ATTEST_LOG_ERROR("[GetProductIKM] Failed to get ikm");
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
int32_t ret = Sha256ValueToAscii(ikmDecrypted, strlen((const char *)ikmDecrypted), ikm, ikmLen);
|
||||
ATTEST_MEM_FREE(ikmDecrypted);
|
||||
if (ret != ATTEST_OK) {
|
||||
ATTEST_LOG_ERROR("[GetProductIKM] failed to Sha256");
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
return ATTEST_OK;
|
||||
}
|
||||
|
||||
static int32_t GetProductToken(const char* challenge, uint8_t* tokenValueHmac, uint8_t tokenValueHmacLen)
|
||||
{
|
||||
if (tokenValueHmac == NULL || tokenValueHmacLen < TOKEN_VALUE_LEN) {
|
||||
ATTEST_LOG_ERROR("[GetProductToken] Invalid parameter");
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
unsigned char salt[SHA256_OUTPUT_SIZE + 1] = {0};
|
||||
int32_t ret = GetProductSalt(salt, SHA256_OUTPUT_SIZE);
|
||||
if (ret == ATTEST_ERR) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
unsigned char ikm[SHA256_OUTPUT_SIZE + 1] = {0};
|
||||
ret = GetProductIKM(ikm, SHA256_OUTPUT_SIZE);
|
||||
if (ret == ATTEST_ERR) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
int infoLen = strlen(challenge) / 2;
|
||||
char *info = (char *)ATTEST_MEM_MALLOC(infoLen + 1);
|
||||
if (info == NULL) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
ret = HEXStringToAscii(challenge, strlen(challenge), info, infoLen);
|
||||
if (ret == ATTEST_ERR) {
|
||||
ATTEST_MEM_FREE(info);
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
unsigned char okm[OKM_INPUT_LEN + 1] = {0};
|
||||
const mbedtls_md_info_t *mdInfo = mbedtls_md_info_from_type(MBEDTLS_MD_SHA256);
|
||||
ret = mbedtls_hkdf(mdInfo, salt, SHA256_OUTPUT_SIZE,
|
||||
ikm, SHA256_OUTPUT_SIZE,
|
||||
(const unsigned char*)info, strlen(info),
|
||||
okm, OKM_INPUT_LEN);
|
||||
ATTEST_MEM_FREE(info);
|
||||
if (ret != ATTEST_OK) {
|
||||
ATTEST_LOG_ERROR("[GetProductToken] HKDF derive key failed, ret = -0x%x", -ret);
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
uint8_t tokenValue[TOKEN_VALUE_LEN + 1] = {0};
|
||||
ret = Base64Encode(okm, OKM_INPUT_LEN, tokenValue, TOKEN_VALUE_LEN);
|
||||
if (ret != ATTEST_OK) {
|
||||
ATTEST_LOG_ERROR("[GetProductToken] Base64 encode symbol info failed, ret = -0x00%x", -ret);
|
||||
return ret;
|
||||
}
|
||||
if (memcpy_s(tokenValueHmac, tokenValueHmacLen, tokenValue, TOKEN_VALUE_LEN) != 0) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t GetProductTokenInfo(const char* challenge, uint8_t* tokenValueHmac, uint8_t tokenValueHmacLen,\
|
||||
uint8_t* tokenId, uint8_t tokenIdLen)
|
||||
{
|
||||
if (tokenValueHmacLen < TOKEN_VALUE_HMAC_LEN || tokenIdLen < TOKEN_VALUE_LEN) {
|
||||
ATTEST_LOG_ERROR("[GetProductTokenInfo] Invalid parameter");
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
TokenInfo tokenInfo;
|
||||
(void)memset_s(&tokenInfo, sizeof(TokenInfo), 0, sizeof(TokenInfo));
|
||||
int32_t ret = AttestReadToken(&tokenInfo);
|
||||
if (ret != TOKEN_UNPRESET) {
|
||||
ATTEST_LOG_ERROR("[GetProductTokenInfo] The token file already exists");
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
memset_s(tokenValueHmac, tokenValueHmacLen, 0, tokenValueHmacLen);
|
||||
memset_s(tokenId, tokenIdLen, 0, tokenIdLen);
|
||||
|
||||
uint8_t tokenValue[TOKEN_VALUE_LEN + 1] = {0};
|
||||
ret = GetProductToken(challenge, tokenValue, TOKEN_VALUE_LEN);
|
||||
if (ret != ATTEST_OK) {
|
||||
ATTEST_LOG_ERROR("[GetProductTokenInfo] Read token failed");
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
if (memcpy_s(tokenId, tokenIdLen, tokenValue, TOKEN_VALUE_LEN) != 0) {
|
||||
ATTEST_LOG_ERROR("[GetProductTokenInfo] memcpy failed");
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
uint8_t hmac[HMAC_SHA256_CIPHER_LEN] = {0};
|
||||
ret = EncryptHmac(challenge, (const uint8_t*)tokenValue, strlen((const char *)tokenValue), hmac, sizeof(hmac));
|
||||
(void)memset_s(tokenValue, TOKEN_VALUE_LEN + 1, 0, TOKEN_VALUE_LEN + 1);
|
||||
if (ret != ATTEST_OK) {
|
||||
ATTEST_LOG_ERROR("[GetProductTokenInfo] Encrypt token value hmac failed, ret = %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = Base64Encode(hmac, sizeof(hmac), tokenValueHmac, tokenValueHmacLen);
|
||||
(void)memset_s(hmac, HMAC_SHA256_CIPHER_LEN, 0, HMAC_SHA256_CIPHER_LEN);
|
||||
if (ret != ATTEST_OK) {
|
||||
ATTEST_LOG_ERROR("[GetProductTokenInfo] Encrypt token value base64 encode failed, ret = %d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int32_t TransTokenVersion(const char* tokenVersion, uint8_t tokenVersionLen)
|
||||
{
|
||||
@@ -444,7 +641,9 @@ static int32_t GetTokenValueDecrypted(uint8_t* tokenValue, uint8_t tokenValueLen
|
||||
int32_t ret = AttestReadToken(&tokenInfo);
|
||||
if (ret == TOKEN_UNPRESET) {
|
||||
ATTEST_LOG_ERROR("[GetTokenValueDecrypted] read tokenInfo failed, ret = %d", ret);
|
||||
#if defined(__ATTEST_ENABLE_PRESET_TOKEN__)
|
||||
ret = GetTokenValueSpecial(tokenValue, tokenValueLen);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -462,7 +661,7 @@ static int32_t GetTokenValueDecrypted(uint8_t* tokenValue, uint8_t tokenValueLen
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t GetTokenValueHmac(const char* challenge, uint8_t* tokenValueHmac, uint8_t tokenValueHmacLen)
|
||||
static int32_t GetTokenValueHmac(const char* challenge, uint8_t* tokenValueHmac, uint8_t tokenValueHmacLen)
|
||||
{
|
||||
ATTEST_LOG_DEBUG("[GetTokenValueHmac] Begin.");
|
||||
if ((challenge == NULL) || (tokenValueHmac == NULL)) {
|
||||
@@ -494,14 +693,16 @@ int32_t GetTokenValueHmac(const char* challenge, uint8_t* tokenValueHmac, uint8_
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t GetTokenId(uint8_t* tokenId, uint8_t tokenIdLen)
|
||||
static int32_t GetTokenId(uint8_t* tokenId, uint8_t tokenIdLen)
|
||||
{
|
||||
TokenInfo tokenInfo;
|
||||
(void)memset_s(&tokenInfo, sizeof(TokenInfo), 0, sizeof(TokenInfo));
|
||||
int32_t ret = AttestReadToken(&tokenInfo);
|
||||
if (ret == TOKEN_UNPRESET) {
|
||||
ATTEST_LOG_ERROR("[GetTokenId] read tokenInfo failed, ret = %d", ret);
|
||||
#if defined(__ATTEST_ENABLE_PRESET_TOKEN__)
|
||||
ret = GetTokenIdSpecial(tokenId, tokenIdLen);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
if (ret != ATTEST_OK) {
|
||||
@@ -517,6 +718,37 @@ int32_t GetTokenId(uint8_t* tokenId, uint8_t tokenIdLen)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t GetTokenValueAndId(const char* challenge, uint8_t* tokenValueHmac, uint8_t tokenValueHmacLen,\
|
||||
uint8_t* tokenId, uint8_t tokenIdLen)
|
||||
{
|
||||
if (tokenValueHmacLen < TOKEN_VALUE_HMAC_LEN || tokenIdLen < TOKEN_VALUE_LEN) {
|
||||
ATTEST_LOG_ERROR("[GetTokenValueAndId] Invalid parameter");
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
int32_t ret = ATTEST_ERR;
|
||||
do {
|
||||
if (GetTokenValueHmac(challenge, tokenValueHmac, tokenValueHmacLen) == ATTEST_OK &&\
|
||||
GetTokenId(tokenId, tokenIdLen) == ATTEST_OK) {
|
||||
ATTEST_LOG_INFO("[GetTokenValueAndId] Get device token success.");
|
||||
ret = ATTEST_OK;
|
||||
break;
|
||||
}
|
||||
#if !defined(__ATTEST_ENABLE_PRESET_TOKEN__)
|
||||
if (GetProductTokenInfo(challenge, tokenValueHmac, tokenValueHmacLen,\
|
||||
tokenId, tokenIdLen) == ATTEST_OK) {
|
||||
ATTEST_LOG_INFO("[GetTokenValueAndId] Get product token success.");
|
||||
ret = ATTEST_OK;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
} while (0);
|
||||
if (ret != ATTEST_OK) {
|
||||
ATTEST_LOG_ERROR("[GetTokenValueAndId] Get token failed.");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t WriteToken(const char* tokenValue, uint8_t tokenValueLen,
|
||||
const char* tokenId, uint8_t tokenIdLen)
|
||||
{
|
||||
|
||||
@@ -187,16 +187,13 @@ int32_t ToLowerStr(char* str, int len)
|
||||
return ATTEST_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encrypt string with sha256 algorithm, and generate uppercase string.
|
||||
*
|
||||
*/
|
||||
int Sha256Value(const unsigned char *src, int srcLen, char *dest, int destLen)
|
||||
int Sha256ValueToAscii(const unsigned char *src, int srcLen, unsigned char *dest, int destLen)
|
||||
{
|
||||
if (src == NULL) {
|
||||
if (src == NULL || srcLen <= 0 || dest == NULL || destLen <= 0) {
|
||||
ATTEST_LOG_ERROR("[Sha256ValueToAscii] Invalid parameter");
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
char buf[DEV_BUF_LENGTH] = {0};
|
||||
|
||||
unsigned char hash[HASH_LENGTH] = {0};
|
||||
|
||||
mbedtls_sha256_context context;
|
||||
@@ -205,11 +202,36 @@ int Sha256Value(const unsigned char *src, int srcLen, char *dest, int destLen)
|
||||
mbedtls_sha256_update_ret(&context, src, srcLen);
|
||||
mbedtls_sha256_finish_ret(&context, hash);
|
||||
|
||||
int32_t ret = ATTEST_OK;
|
||||
for (size_t i = 0; i < HASH_LENGTH; i++) {
|
||||
unsigned char value = hash[i];
|
||||
int ret = ATTEST_OK;
|
||||
if (memcpy_s(dest, destLen, hash, HASH_LENGTH) != 0) {
|
||||
ATTEST_LOG_ERROR("[Sha256ValueToAscii] Failed to memcpy");
|
||||
ret = ATTEST_ERR;
|
||||
}
|
||||
(void)memset_s(hash, HASH_LENGTH, 0, HASH_LENGTH);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encrypt string with sha256 algorithm, and generate uppercase string.
|
||||
*
|
||||
*/
|
||||
int Sha256Value(const unsigned char *src, int srcLen, char *dest, int destLen)
|
||||
{
|
||||
if (src == NULL || srcLen <= 0 || dest == NULL || destLen <= 0) {
|
||||
ATTEST_LOG_ERROR("[Sha256Value] Invalid parameter");
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
char buf[DEV_BUF_LENGTH] = {0};
|
||||
unsigned char hash[HASH_LENGTH] = {0};
|
||||
int32_t ret = Sha256ValueToAscii(src, srcLen, hash, HASH_LENGTH);
|
||||
if (ret != ATTEST_OK) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
for (int i = 0; i < HASH_LENGTH; i++) {
|
||||
(void)memset_s(buf, DEV_BUF_LENGTH, 0, DEV_BUF_LENGTH);
|
||||
if (sprintf_s(buf, sizeof(buf), "%02X", value) < 0) {
|
||||
// generate uppercase string
|
||||
if (sprintf_s(buf, sizeof(buf), "%02X", hash[i]) < 0) {
|
||||
ret = ATTEST_ERR;
|
||||
break;
|
||||
}
|
||||
@@ -255,3 +277,44 @@ void AttestMemFree(void **point)
|
||||
*point = NULL;
|
||||
}
|
||||
|
||||
static int32_t HexToNumber(char inputChr)
|
||||
{
|
||||
int retNumber = 0;
|
||||
if (inputChr >= '0' && inputChr <= '9') {
|
||||
retNumber = inputChr - '0';
|
||||
} else if (inputChr >= 'a' && inputChr <= 'f') {
|
||||
retNumber = DECIMAL_BASE + inputChr - 'a';
|
||||
} else if (inputChr >= 'A' && inputChr <= 'F') {
|
||||
retNumber = DECIMAL_BASE + inputChr - 'A';
|
||||
} else {
|
||||
retNumber = ATTEST_ERR;
|
||||
}
|
||||
return retNumber;
|
||||
}
|
||||
|
||||
int32_t HEXStringToAscii(const char* input, int32_t inputLen, char* output, int32_t outputLen)
|
||||
{
|
||||
if (input == NULL || inputLen <= 0 || output == NULL || (inputLen % ATTEST_EVEN_NUMBER == 1)) {
|
||||
ATTEST_LOG_ERROR("[HEXStringToAscii] Invaild paramter");
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
if (outputLen < (inputLen / ATTEST_EVEN_NUMBER)) {
|
||||
ATTEST_LOG_ERROR("[HEXStringToAscii] outputLen is shorter than required");
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
int tempLen = 0;
|
||||
int32_t ret = ATTEST_OK;
|
||||
for(int i = 0; i < inputLen; ) {
|
||||
int highNumber = HexToNumber(input[i]);
|
||||
int lowNumber = HexToNumber(input[i + 1]);
|
||||
if (highNumber == ATTEST_ERR || lowNumber == ATTEST_ERR) {
|
||||
ret = ATTEST_ERR;
|
||||
break;
|
||||
}
|
||||
output[tempLen++] = highNumber * HEXADECIMAL_BASE + lowNumber;
|
||||
i += ATTEST_EVEN_NUMBER;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -133,16 +133,18 @@ static char* StrdupMemInfo(const char* input)
|
||||
if (input == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
size_t len = strlen(input) + 1;
|
||||
if (len == 1) {
|
||||
size_t inputLen = strlen(input);
|
||||
if (inputLen == 0 || inputLen >= MAX_ATTEST_MALLOC_BUFF_SIZE) {
|
||||
return NULL;
|
||||
}
|
||||
char* out = malloc(len);
|
||||
|
||||
size_t outputLen = inputLen + 1;
|
||||
char* out = malloc(outputLen);
|
||||
if (out == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
(void)memset_s(out, len, 0, len);
|
||||
if (memcpy_s(out, len, input, strlen(input)) != 0) {
|
||||
(void)memset_s(out, outputLen, 0, outputLen);
|
||||
if (memcpy_s(out, outputLen, input, inputLen) != 0) {
|
||||
free(out);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <securec.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <pthread.h>
|
||||
#include <sys/prctl.h>
|
||||
#include "attest_utils.h"
|
||||
#include "attest_utils_log.h"
|
||||
#include "attest_utils_timer.h"
|
||||
@@ -26,6 +27,9 @@
|
||||
|
||||
static void AttestTimerCallback(union sigval attestTimer)
|
||||
{
|
||||
#ifdef HAVE_PTHREAD_SETNAME_NP
|
||||
(void)pthread_setname_np(pthread_self(), ATTEST_TIMER_TASK_ID); // set pthread name, at most 15 bytes.
|
||||
#endif
|
||||
AttestTimerInfo *tmpTimerInfo = (AttestTimerInfo *)attestTimer.sival_ptr;
|
||||
if (tmpTimerInfo->type == ATTEST_TIMER_TYPE_ONCE) {
|
||||
tmpTimerInfo->status = ATTEST_TIMER_STATUS_STOP;
|
||||
@@ -123,7 +127,7 @@ int32_t AttestStartTimerTask(AttestTimerType isOnce, uint32_t milliseconds,
|
||||
if (*timerHandle != NULL) {
|
||||
AttestTimerInfo *tmpTimerInfo = (AttestTimerInfo *)timerHandle;
|
||||
if (tmpTimerInfo->timerId != 0) {
|
||||
ATTEST_LOG_ERROR("[AttestStartTimerTask] timerId[%d] already exists", tmpTimerInfo->timerId);
|
||||
ATTEST_LOG_ERROR("[AttestStartTimerTask] timerId already exists");
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
+21
-9
@@ -11,14 +11,15 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/lite/config/test.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/lite/config/test.gni")
|
||||
import("//test/xts/device_attest_lite/build/devattestconfig.gni")
|
||||
import("//test/xts/device_attest_lite/services/core/attestsource.gni")
|
||||
|
||||
if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") {
|
||||
unittest("device_attest_tdd") {
|
||||
output_extension = "bin"
|
||||
output_dir = "$root_out_dir/test/unittest/device_attest_lite"
|
||||
cflags = [
|
||||
"-ftrapv",
|
||||
"-Werror",
|
||||
@@ -29,29 +30,40 @@ if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") {
|
||||
"-Wfloat-equal",
|
||||
"-Wdate-time",
|
||||
"-fPIC",
|
||||
"-pthread",
|
||||
]
|
||||
|
||||
defines = [ "MBEDTLS_ALLOW_PRIVATE_ACCESS" ]
|
||||
|
||||
if (enable_attest_preset_token) {
|
||||
defines += [ "__ATTEST_ENABLE_PRESET_TOKEN__" ]
|
||||
}
|
||||
include_dirs = include_core_dirs
|
||||
include_dirs += [
|
||||
".",
|
||||
"./include",
|
||||
"${devattest_path}/services/core",
|
||||
"${devattest_path}/interfaces/innerkits",
|
||||
"${devattest_path}/common",
|
||||
"${devattest_path}/common/log",
|
||||
"${devattest_path}/common/small",
|
||||
]
|
||||
sources = [
|
||||
"attest_tdd_data_transfer.c",
|
||||
"attest_tdd_mock_hal.c",
|
||||
"attest_tdd_mock_net.c",
|
||||
"attest_tdd_mock_property.c",
|
||||
"attest_tdd_test.cpp",
|
||||
"./src/attest_tdd_data_transfer.c",
|
||||
"./src/attest_tdd_mock_hal.c",
|
||||
"./src/attest_tdd_mock_net.c",
|
||||
"./src/attest_tdd_mock_property.c",
|
||||
"./src/attest_tdd_test.cpp",
|
||||
]
|
||||
sources += [
|
||||
"${devattest_path}/services/core/small/adapter/attest_adapter_network_config.c",
|
||||
"${devattest_path}/services/core/small/attest/attest_service_pcid.c",
|
||||
"${devattest_path}/services/core/small/utils/attest_utils_file_detail.c",
|
||||
]
|
||||
sources += sources_common
|
||||
|
||||
sources -= [
|
||||
"${devattest_path}/services/core/security/attest_security_ticket.c",
|
||||
"${devattest_path}/services/core/adapter/attest_adapter.c",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"$ohos_product_adapter_dir/utils/token:haltoken_shared",
|
||||
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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 <stdbool.h>
|
||||
#include <securec.h>
|
||||
#include "attest_utils_log.h"
|
||||
#include "attest_adapter_mock.h"
|
||||
#include "attest_type.h"
|
||||
#include "attest_tdd_data_transfer.h"
|
||||
#include "attest_tdd_mock_config.h"
|
||||
|
||||
static bool g_isFirstToken = true;
|
||||
|
||||
static const char* ATTEST_FIRST_TOKENID = "57,65,104,109,101,122,89,84,112,99,50,88,56,57,114,71,48,66,54,66,52,73,\
|
||||
111,109,103,119,104,75,82,69,114,76,102,78,109,89,121,89,110,113,106,72,109,71,80,102,102,79,87,55,43,113,75,89,55,\
|
||||
117,47,85,67,68,114,119,103,106,89,49,73,87,90,56,105,81,79,52,73,78,113,79,105,105,102,78,89,52,100,101,71,54,113,77,\
|
||||
49,106,113,78,107,50,43,85,52,55,54,83,76,77,105,98,121,109,121,55,112,102,78,68,84,80,43,104,83,106,72,120,72,65,\
|
||||
101,70,86,65,65,81,54,53,76,109,101,98,56,118,43,51,111,108,83,108,49,48,48,48,0";
|
||||
static const char* ATTEST_FIRST_TOKEVALUE = "89,49,73,87,90,56,105,81,79,52,73,78,113,79,105,105,102,78,89,52,100,101,\
|
||||
71,54,113,77,49,106,113,78,107,50,43,85,52,55,54,83,76,77,105,98,121,109,121,55,112,102,78,68,84,80,43,104,83,106,72,\
|
||||
120,72,65,101,70,86,65,65,81,54,53,76,109,101,98,56,118,43,51,111,108,83,108,49,48,48,48,0";
|
||||
static const char* ATTEST_FIRST_SALT = "65,81,54,53,76,109,101,98,56,118,43,51,111,108,83,108,49,48,48,48,0";
|
||||
static const char* ATTEST_FIRST_VERSION = "49,48,48,48,0";
|
||||
|
||||
static const char* ATTEST_SECOND_TOKENID = "74,106,77,70,108,84,79,90,73,84,104,54,119,115,121,108,50,87,72,55,86,113,\
|
||||
111,43,65,102,102,114,48,108,57,52,120,48,70,111,78,100,49,111,71,82,48,113,49,73,121,67,50,84,82,122,112,55,118,\
|
||||
104,107,103,74,48,110,83,75,77,87,89,88,108,73,43,84,73,111,118,48,65,109,89,117,66,66,99,117,101,120,102,48,78,\
|
||||
102,76,66,90,98,72,53,106,114,47,98,99,113,81,85,80,107,54,53,98,57,86,50,82,48,107,108,82,121,72,118,113,101,54,\
|
||||
108,70,107,79,122,108,130,1,1,1,44,1,1,1,65,1,1,1,217,1,1,1,49,48,48,48,0";
|
||||
static const char* ATTEST_SECOND_TOKEVALUE = "87,89,88,108,73,43,84,73,111,118,48,65,109,89,117,66,66,99,117,101,120,\
|
||||
102,48,78,102,76,66,90,98,72,53,106,114,47,98,99,113,81,85,80,107,54,53,98,57,86,50,82,48,107,108,82,121,72,118,113,\
|
||||
101,54,108,70,107,79,122,108,130,1,1,1,44,1,1,1,65,1,1,1,217,1,1,1,49,48,48,48,0";
|
||||
static const char* ATTEST_SECOND_SALT = "130,1,1,1,44,1,1,1,65,1,1,1,217,1,1,1,49,48,48,48,0";
|
||||
static const char* ATTEST_SECOND_VERSION = "49,48,48,48,0";
|
||||
|
||||
// 读取Manufacturekey
|
||||
int32_t AttestGetManufacturekey(uint8_t manufacturekey[], uint32_t len)
|
||||
{
|
||||
return OsGetAcKeyStub((char*)manufacturekey, len);
|
||||
}
|
||||
|
||||
// 读取ProductId
|
||||
int32_t AttestGetProductId(uint8_t productId[], uint32_t len)
|
||||
{
|
||||
if ((productId == NULL) || (len == 0)) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
const char productIdBuf[] = "OH00004O";
|
||||
uint32_t productIdLen = strlen(productIdBuf);
|
||||
if (len < productIdLen) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
int ret = memcpy_s(productId, len, productIdBuf, productIdLen);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// 读取ProductKey
|
||||
int32_t AttestGetProductKey(uint8_t productKey[], uint32_t len)
|
||||
{
|
||||
return OsGetProdKeyStub((char*)productKey, len);
|
||||
}
|
||||
|
||||
int32_t AttestWriteToken(TokenInfo* tokenInfo)
|
||||
{
|
||||
(void)tokenInfo;
|
||||
return ATTEST_OK;
|
||||
}
|
||||
|
||||
int32_t AttestReadToken(TokenInfo* tokenInfo)
|
||||
{
|
||||
ATTEST_LOG_INFO("[AttestTdd] In AttestReadToken.");
|
||||
if (tokenInfo == NULL) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
int ret = -1;
|
||||
uint8_t *out = (uint8_t *)tokenInfo->tokenId;
|
||||
const char *tokenId = g_isFirstToken ? ATTEST_FIRST_TOKENID : ATTEST_SECOND_TOKENID;
|
||||
ret = AttestSeriaToBinary(tokenId, &out, TOKEN_ID_ENCRYPT_LEN);
|
||||
if (ret != ATTEST_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
out = (uint8_t *)tokenInfo->tokenValue;
|
||||
const char *tokenValue = g_isFirstToken ? ATTEST_FIRST_TOKEVALUE : ATTEST_SECOND_TOKEVALUE;
|
||||
ret = AttestSeriaToBinary(tokenValue, &out, TOKEN_VALUE_ENCRYPT_LEN);
|
||||
if (ret != ATTEST_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
out = (uint8_t *)tokenInfo->salt;
|
||||
const char *salt = g_isFirstToken ? ATTEST_FIRST_SALT : ATTEST_SECOND_SALT;
|
||||
ret = AttestSeriaToBinary(salt, &out, SALT_ENCRYPT_LEN);
|
||||
if (ret != ATTEST_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
out = (uint8_t *)tokenInfo->version;
|
||||
const char *version = g_isFirstToken ? ATTEST_FIRST_VERSION : ATTEST_SECOND_VERSION;
|
||||
ret = AttestSeriaToBinary(version, &out, VERSION_ENCRYPT_LEN);
|
||||
if (ret != ATTEST_OK) {
|
||||
return ret;
|
||||
}
|
||||
ATTEST_LOG_INFO("[AttestTdd] out AttestReadToken.");
|
||||
|
||||
return ATTEST_OK;
|
||||
}
|
||||
@@ -1,514 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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 <securec.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include "attest_error.h"
|
||||
#include "attest_utils_log.h"
|
||||
#include "attest_utils.h"
|
||||
#include "attest_entry.h"
|
||||
#include "attest_result_info.h"
|
||||
#include "attest_type.h"
|
||||
#include "attest_network.h"
|
||||
#include "attest_service_active.h"
|
||||
#include "attest_service_auth.h"
|
||||
#include "attest_service_challenge.h"
|
||||
#include "attest_service_device.h"
|
||||
#include "attest_service.h"
|
||||
#include "attest_service_device.h"
|
||||
#include "attest_security_token.h"
|
||||
#include "attest_service_reset.h"
|
||||
#include "attest_tdd_mock_config.h"
|
||||
#include "attest_network.h"
|
||||
#include "attest_adapter.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
namespace DevAttest {
|
||||
static const int32_t TDD_AUTH_RESULT = 0;
|
||||
|
||||
static const int32_t ATTEST_GET_CHANLLEGE = 0;
|
||||
static const int32_t ATTEST_RESET = 1;
|
||||
static const int32_t ATTEST_ACTIVE = 2;
|
||||
static const int32_t ATTEST_AUTH = 3;
|
||||
|
||||
static const int32_t ATTEST_CHANLLEGE_LEN = 64;
|
||||
|
||||
static const char* ATTEST_RESET_EXPECT_TOKEN = "WOetrEFOcjw8Px2TZNmq3ckoMzXEkkoLfgQeGNnG3XA=";
|
||||
|
||||
static const char* ATTEST_AUTH_EXPECT_RESULT = "{\"authStats\":\".eyJhdXRoUmVzdWx0IjowLCJhdXRoVHlwZSI6IlRPS0VOX0VO\
|
||||
QUJMRSIsImV4cGlyZVRpbWUiOjE2ODMzNzM2NzE2NzQsImtpdFBvbGljeSI6W10sInNvZnR3YXJlUmVzdWx0IjozMDAwMiwic29mdHdhcmVSZXN1bHRE\
|
||||
ZXRhaWwiOnsicGF0Y2hMZXZlbFJlc3VsdCI6MzAwMDgsInBjaWRSZXN1bHQiOjMwMDExLCJyb290SGFzaFJlc3VsdCI6MzAwMDksInZlcnNpb25JZFJlc\
|
||||
3VsdCI6MzAwMDJ9LCJ1ZGlkIjoiODFDOTQ0NTI3OUEzQTQxN0Q0MTU5RkRGQzYyNjkxQkM4REEwMDJFODQ2M0M3MEQyM0FCNENCRjRERjk4MjYxQy\
|
||||
IsInZlcnNpb25JZCI6ImRlZmF1bHQvaHVhLXdlaS9rZW1pbi9kZWZhdWx0L09wZW5IYXJtb255LTQuMC4zLjIoQ2FuYXJ5MSkvb2hvcy9tYXgvMTAv\
|
||||
T3Blbkhhcm1vbnkgMi4zIGJldGEvZGVidWcifQ.\",\
|
||||
\"errcode\":0,\
|
||||
\"ticket\":\"svnR0unsciaFi7S4hcpBa/LCSiYwNSt6\",\
|
||||
\"token\":\"yh9te54pfTb91CrSqpD5fQsVBA/etKNb\",\
|
||||
\"uuid\":\"156dcff8-0ab0-4521-ac8f-ba682e6ca5a0\"\
|
||||
}3";
|
||||
|
||||
static const char* ATTEST_AUTH_GEN_TOKEN = "5HWNhKgnJ+sVZM313rCsNa3QK2RhrC4+bClH9SX5O84=";
|
||||
static const char* ATTEST_AUTH_CHAP = "a81441e3c0d8d6a78907fa0888f9241be9591c4d6b7a533318b010fb2c3d9b80";
|
||||
static const int64_t ATTEST_AUTH_CHAP_TIME = 1449458719;
|
||||
|
||||
static const char* ATTEST_ACTIVE_EXPECT_TOKEN = "648390656";
|
||||
static const char* ATTEST_ACTIVE_CHAP = "01824812bda06b33e3c76ac8cf3f6d2153867ce39db08f625203a350d5635ac9";
|
||||
static const int64_t ATTEST_ACTIVE_CHAP_TIME = 1449459365;
|
||||
|
||||
static const int64_t ATTEST_EXPIRRTIME = -584928741;
|
||||
static const int32_t ATTEST_HARDWARERESULT = 0;
|
||||
|
||||
static const char* ATTEST_REST_ERROR_EXPECT_RESULT = "15003";
|
||||
|
||||
static const char* ATTEST_RESET_EXPECT_CHAP = "39a9d04d41617162893c3312ceb030acac8d8bd0cc9fcebcab5402a43891341d";
|
||||
static const int64_t ATTEST_RESET_EXPECT_CHAP_TIME = 1449458490;
|
||||
|
||||
static const char* ATTEST_TICKET = "svnR0unsciaFi7S4hcpBa/LCSiYwNSt6";
|
||||
static const char* ATTEST_STATUS = ".eyJhdXRoUmVzdWx0IjowLCJhdXRoVHlwZSI6IlRPS0VOX0VOQUJMRSI\
|
||||
sImV4cGlyZVRpbWUiOjE2ODMzNzM2NzE2NzQsImtpdFBvbGljeSI6W10sInNvZnR3YXJlUmVzdWx0IjozMDAwMiwic29mdHdhcmVSZXN1bHREZXRh\
|
||||
aWwiOnsicGF0Y2hMZXZlbFJlc3VsdCI6MzAwMDgsInBjaWRSZXN1bHQiOjMwMDExLCJyb290SGFzaFJlc3VsdCI6MzAwMDksInZlcnNpb25JZFJlc\
|
||||
3VsdCI6MzAwMDJ9LCJ1ZGlkIjoiODFDOTQ0NTI3OUEzQTQxN0Q0MTU5RkRGQzYyNjkxQkM4REEwMDJFODQ2M0M3MEQyM0FCNENCRjRERjk4MjYxQy\
|
||||
IsInZlcnNpb25JZCI6ImRlZmF1bHQvaHVhLXdlaS9rZW1pbi9kZWZhdWx0L09wZW5IYXJtb255LTQuMC4zLjIoQ2FuYXJ5MSkvb2hvcy9tYXgvMTAv\
|
||||
T3Blbkhhcm1vbnkgMi4zIGJldGEvZGVidWcifQ.";
|
||||
|
||||
class AttestTddTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
|
||||
static void TearDownTestCase(void);
|
||||
|
||||
void SetUp();
|
||||
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void AttestTddTest::SetUpTestCase(void)
|
||||
{
|
||||
// input testsuit setup step,setup invoked before all testcases
|
||||
(void)InitSysData();
|
||||
(void)InitNetworkServerInfo();
|
||||
}
|
||||
|
||||
void AttestTddTest::TearDownTestCase(void)
|
||||
{
|
||||
// input testsuit teardown step,teardown invoked after all testcases
|
||||
}
|
||||
|
||||
void AttestTddTest::SetUp()
|
||||
{
|
||||
// input testcase setup step,setup invoked before each testcases
|
||||
}
|
||||
|
||||
void AttestTddTest::TearDown()
|
||||
{
|
||||
// input testcase teardown step,teardown invoked after each testcases
|
||||
}
|
||||
|
||||
static AuthResult *GetAuthResult()
|
||||
{
|
||||
AuthResult *authResult = CreateAuthResult();
|
||||
if (authResult == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
int32_t ret = ParseAuthResultResp(ATTEST_AUTH_EXPECT_RESULT, authResult);
|
||||
if (ret != ATTEST_OK) {
|
||||
DestroyAuthResult(&authResult);
|
||||
return nullptr;
|
||||
}
|
||||
return authResult;
|
||||
}
|
||||
|
||||
static DevicePacket* TddGenActiveMsg()
|
||||
{
|
||||
if (ATTEST_CHANLLEGE_LEN != strlen(ATTEST_ACTIVE_CHAP)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
AuthResult *authResult = GetAuthResult();
|
||||
if (authResult == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DevicePacket* reqMsg = NULL;
|
||||
char attestChallengeActive[ATTEST_CHANLLEGE_LEN + 1] = {0};
|
||||
errno_t rc = memcpy_s(attestChallengeActive, ATTEST_CHANLLEGE_LEN + 1,
|
||||
ATTEST_ACTIVE_CHAP, ATTEST_CHANLLEGE_LEN);
|
||||
if (rc != EOK) {
|
||||
ATTEST_LOG_ERROR("[TddGenResetMsg] memset failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ChallengeResult challenge;
|
||||
challenge.challenge = attestChallengeActive;
|
||||
challenge.currentTime = ATTEST_ACTIVE_CHAP_TIME;
|
||||
int32_t ret = GenActiveMsg(authResult, &challenge, &reqMsg);
|
||||
DestroyAuthResult(&authResult);
|
||||
if (ret != ATTEST_OK) {
|
||||
return nullptr;
|
||||
}
|
||||
return reqMsg;
|
||||
}
|
||||
|
||||
static DevicePacket* TddGenAuthMsg()
|
||||
{
|
||||
if (ATTEST_CHANLLEGE_LEN != strlen(ATTEST_AUTH_CHAP)) {
|
||||
return NULL;
|
||||
}
|
||||
DevicePacket* reqMsg = NULL;
|
||||
char attestChallengeAuth[ATTEST_CHANLLEGE_LEN + 1] = {0};
|
||||
errno_t rc = memcpy_s(attestChallengeAuth, ATTEST_CHANLLEGE_LEN + 1,
|
||||
ATTEST_AUTH_CHAP, ATTEST_CHANLLEGE_LEN);
|
||||
if (rc != EOK) {
|
||||
ATTEST_LOG_ERROR("[TddGenResetMsg] memset failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ChallengeResult challenge;
|
||||
challenge.challenge = attestChallengeAuth;
|
||||
challenge.currentTime = ATTEST_AUTH_CHAP_TIME;
|
||||
int32_t ret = GenAuthMsg(&challenge, &reqMsg);
|
||||
if (ret != ATTEST_OK) {
|
||||
return nullptr;
|
||||
}
|
||||
return reqMsg;
|
||||
}
|
||||
|
||||
static DevicePacket* TddGenResetMsg()
|
||||
{
|
||||
if (ATTEST_CHANLLEGE_LEN != strlen(ATTEST_RESET_EXPECT_CHAP)) {
|
||||
return nullptr;
|
||||
}
|
||||
DevicePacket* reqMsg = NULL;
|
||||
char attestChallengeReset[ATTEST_CHANLLEGE_LEN + 1] = {0};
|
||||
errno_t rc = memcpy_s(attestChallengeReset, ATTEST_CHANLLEGE_LEN + 1,
|
||||
ATTEST_RESET_EXPECT_CHAP, ATTEST_CHANLLEGE_LEN);
|
||||
if (rc != EOK) {
|
||||
ATTEST_LOG_ERROR("[TddGenResetMsg] memset failed");
|
||||
return nullptr;
|
||||
}
|
||||
ChallengeResult challenge;
|
||||
challenge.challenge = attestChallengeReset;
|
||||
challenge.currentTime = ATTEST_RESET_EXPECT_CHAP_TIME;
|
||||
int32_t ret = GenResetMsg(&challenge, &reqMsg);
|
||||
if (ret != ATTEST_OK) {
|
||||
return nullptr;
|
||||
}
|
||||
return reqMsg;
|
||||
}
|
||||
|
||||
void WriteAuthStatus()
|
||||
{
|
||||
int32_t ret = FlushAuthResult(ATTEST_TICKET, ATTEST_STATUS);
|
||||
EXPECT_TRUE((ret == ATTEST_OK));
|
||||
}
|
||||
|
||||
void TestGetAuthStatus(char **status)
|
||||
{
|
||||
int32_t ret = GetAuthStatus(status);
|
||||
EXPECT_TRUE((ret == ATTEST_OK));
|
||||
}
|
||||
|
||||
static void FreeAuthStatus(AuthStatus* authStatus)
|
||||
{
|
||||
if (authStatus->versionId != NULL) {
|
||||
free(authStatus->versionId);
|
||||
}
|
||||
if (authStatus->authType != NULL) {
|
||||
free(authStatus->authType);
|
||||
}
|
||||
if (authStatus->softwareResultDetail != NULL) {
|
||||
free(authStatus->softwareResultDetail);
|
||||
}
|
||||
free(authStatus);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestInitNetWort001
|
||||
* @tc.desc: Test init network.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestInitNetWort001, TestSize.Level1)
|
||||
{
|
||||
int ret = InitNetworkServerInfo();
|
||||
EXPECT_TRUE(ret == ATTEST_OK);
|
||||
ret = D2CConnect();
|
||||
EXPECT_TRUE(ret == ATTEST_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestSendActiveMsg001
|
||||
* @tc.desc: Test send active msg.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestSendActiveMsg001, TestSize.Level1)
|
||||
{
|
||||
(void)InitNetworkServerInfo();
|
||||
(void)D2CConnect();
|
||||
|
||||
g_netType = ATTEST_ACTIVE;
|
||||
DevicePacket* reqMsg = TddGenActiveMsg();
|
||||
ASSERT_TRUE(reqMsg != NULL);
|
||||
|
||||
char* respMsg = NULL;
|
||||
int32_t ret = SendActiveMsg(reqMsg, &respMsg);
|
||||
EXPECT_TRUE((ret == ATTEST_OK) && (respMsg != NULL));
|
||||
if (respMsg == NULL) {
|
||||
ATTEST_LOG_ERROR("[SendActiveMsgTdd] respMsg is NULL.");
|
||||
return;
|
||||
}
|
||||
if (ret != ATTEST_OK) {
|
||||
free(respMsg);
|
||||
ATTEST_LOG_ERROR("[SendActiveMsgTdd] Send active message failed, ret = %d.", ret);
|
||||
return;
|
||||
}
|
||||
const char* ATTEST_ACTIVE_EXPECT_RESULT = "{\"errcode\":0}";
|
||||
EXPECT_TRUE(strcmp(ATTEST_ACTIVE_EXPECT_RESULT, respMsg) == 0);
|
||||
free(respMsg);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestParseActiveResult001
|
||||
* @tc.desc: Test parse active result,result is ok.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestParseActiveResult001, TestSize.Level1)
|
||||
{
|
||||
const char *input = "{\"errcode\":0}";
|
||||
int32_t ret = ParseActiveResult(input);
|
||||
EXPECT_TRUE(ret == ATTEST_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestParseActiveResult002
|
||||
* @tc.desc: Test parse active result,result is error.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestParseActiveResult002, TestSize.Level1)
|
||||
{
|
||||
const char *input = "{\"errcode\":\"-32s\"}";
|
||||
int32_t ret = ParseActiveResult(input);
|
||||
EXPECT_TRUE((ret != ATTEST_OK));
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestGetAuthStatus001
|
||||
* @tc.desc: Test get authStatus.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestGetAuthStatus001, TestSize.Level1)
|
||||
{
|
||||
WriteAuthStatus();
|
||||
char *status = nullptr;
|
||||
TestGetAuthStatus(&status);
|
||||
EXPECT_TRUE((status != nullptr));
|
||||
if (status == nullptr) {
|
||||
return;
|
||||
}
|
||||
EXPECT_TRUE(strcmp(ATTEST_STATUS, status) == 0);
|
||||
free(status);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestDecodeAuthStatus001
|
||||
* @tc.desc: Test decode auth status.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestDecodeAuthStatus001, TestSize.Level1)
|
||||
{
|
||||
WriteAuthStatus();
|
||||
char *status = nullptr;
|
||||
TestGetAuthStatus(&status);
|
||||
AuthStatus* outStatus = CreateAuthStatus();
|
||||
EXPECT_TRUE((outStatus != nullptr));
|
||||
if (outStatus == nullptr) {
|
||||
return;
|
||||
}
|
||||
int32_t ret = DecodeAuthStatus(status, outStatus);
|
||||
EXPECT_TRUE(ret == ATTEST_OK);
|
||||
SoftwareResultDetail* detail = outStatus->softwareResultDetail;
|
||||
EXPECT_TRUE((outStatus->versionId != nullptr) && (outStatus->authType != nullptr) && (detail != nullptr));
|
||||
if ((outStatus->versionId == nullptr) || (outStatus->authType == nullptr) || (detail == nullptr)) {
|
||||
FreeAuthStatus(outStatus);
|
||||
return;
|
||||
}
|
||||
const char* ATTEST_AUTH_TYPE = "TOKEN_ENABLE";
|
||||
EXPECT_TRUE(strcmp(outStatus->authType, ATTEST_AUTH_TYPE) == 0);
|
||||
EXPECT_TRUE((outStatus->hardwareResult == ATTEST_HARDWARERESULT));
|
||||
FreeAuthStatus(outStatus);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestCheckExpireTime001
|
||||
* @tc.desc: Test check auth result.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestCheckExpireTime001, TestSize.Level1)
|
||||
{
|
||||
AuthStatus* outStatus = CreateAuthStatus();
|
||||
EXPECT_TRUE(outStatus != nullptr);
|
||||
if (outStatus == nullptr) {
|
||||
return;
|
||||
}
|
||||
outStatus->expireTime = 19673222;
|
||||
uint64_t currentTime = 19673223;
|
||||
int32_t ret = CheckExpireTime(outStatus, currentTime);
|
||||
EXPECT_TRUE(ret != ATTEST_OK);
|
||||
outStatus->expireTime = 19673222;
|
||||
currentTime = 19673221;
|
||||
ret = CheckExpireTime(outStatus, currentTime);
|
||||
EXPECT_TRUE(ret == ATTEST_OK);
|
||||
free(outStatus);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestGenAuthMsg001
|
||||
* @tc.desc: Test gen auth msg.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestGenAuthMsg001, TestSize.Level1)
|
||||
{
|
||||
DevicePacket* reqMsg = TddGenAuthMsg();
|
||||
ASSERT_TRUE((reqMsg != nullptr));
|
||||
|
||||
char *outToken = reqMsg->tokenInfo.token;
|
||||
EXPECT_TRUE(outToken != nullptr);
|
||||
if (outToken == NULL) {
|
||||
FREE_DEVICE_PACKET(reqMsg);
|
||||
return;
|
||||
}
|
||||
EXPECT_TRUE(strcmp(outToken, ATTEST_AUTH_GEN_TOKEN) == 0);
|
||||
FREE_DEVICE_PACKET(reqMsg);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestParseAuthResultResp001
|
||||
* @tc.desc: Test parse auth result resp.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestParseAuthResultResp001, TestSize.Level1)
|
||||
{
|
||||
AuthResult *authResult = GetAuthResult();
|
||||
ASSERT_TRUE(authResult != nullptr);
|
||||
|
||||
EXPECT_TRUE((authResult->ticket != nullptr) && (authResult->tokenValue != nullptr) &&
|
||||
(authResult->authStatus != nullptr));
|
||||
if (authResult->ticket != nullptr) {
|
||||
EXPECT_TRUE(strcmp(authResult->ticket, ATTEST_TICKET) == 0);
|
||||
}
|
||||
DestroyAuthResult(&authResult);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestGetChallenge001
|
||||
* @tc.desc: Test get reset challenge.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestGetChallenge001, TestSize.Level1)
|
||||
{
|
||||
g_netType = ATTEST_GET_CHANLLEGE;
|
||||
ChallengeResult* challenge = NULL;
|
||||
int32_t ret = GetChallenge(&challenge, ATTEST_ACTION_RESET);
|
||||
EXPECT_TRUE(ret == ATTEST_OK);
|
||||
EXPECT_TRUE(challenge != NULL);
|
||||
if (ret != ATTEST_OK) {
|
||||
FREE_CHALLENGE_RESULT(challenge);
|
||||
ATTEST_LOG_ERROR("[AttestTdd] GetChallenge failed, ret = %d.", ret);
|
||||
return;
|
||||
}
|
||||
EXPECT_TRUE(strcmp(ATTEST_RESET_EXPECT_CHAP, challenge->challenge) == 0);
|
||||
FREE_CHALLENGE_RESULT(challenge);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestGenResetMsg001
|
||||
* @tc.desc: Test gen reset msg.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestGenResetMsg001, TestSize.Level1)
|
||||
{
|
||||
DevicePacket* reqMsg = TddGenResetMsg();
|
||||
EXPECT_TRUE((reqMsg != nullptr));
|
||||
if (reqMsg == nullptr) {
|
||||
return;
|
||||
}
|
||||
char *outToken = reqMsg->tokenInfo.token;
|
||||
EXPECT_TRUE(outToken != nullptr);
|
||||
if (outToken == NULL) {
|
||||
FREE_DEVICE_PACKET(reqMsg);
|
||||
return;
|
||||
}
|
||||
EXPECT_TRUE(strcmp(ATTEST_RESET_EXPECT_TOKEN, outToken) == 0);
|
||||
FREE_DEVICE_PACKET(reqMsg);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestSendResetMsg001
|
||||
* @tc.desc: Test send reset msg.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestSendResetMsg001, TestSize.Level1)
|
||||
{
|
||||
g_netType = ATTEST_RESET;
|
||||
DevicePacket* reqMsg = TddGenResetMsg();
|
||||
if (reqMsg == NULL) {
|
||||
return;
|
||||
}
|
||||
char* respMsg = NULL;
|
||||
int32_t ret = SendResetMsg(reqMsg, &respMsg);
|
||||
EXPECT_TRUE((ret == ATTEST_OK) && (respMsg != NULL));
|
||||
if (respMsg == NULL) {
|
||||
FREE_DEVICE_PACKET(reqMsg);
|
||||
ATTEST_LOG_ERROR("[SendResetTdd] respMsg is NULL.");
|
||||
return;
|
||||
}
|
||||
if (ret != ATTEST_OK) {
|
||||
FREE_DEVICE_PACKET(reqMsg);
|
||||
free(respMsg);
|
||||
ATTEST_LOG_ERROR("[SendResetMsgTdd] Send reset message failed, ret = %d.", ret);
|
||||
return;
|
||||
}
|
||||
ATTEST_LOG_ERROR("[SendResetTdd] respMsg is NULL.respMsg = %s", respMsg);
|
||||
EXPECT_TRUE(strstr(respMsg, ATTEST_REST_ERROR_EXPECT_RESULT) != nullptr);
|
||||
free(respMsg);
|
||||
FREE_DEVICE_PACKET(reqMsg);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestQueryAttestStatus001
|
||||
* @tc.desc: Test query attest status.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestQueryAttestStatus001, TestSize.Level1)
|
||||
{
|
||||
AuthResult *authResult = GetAuthResult();
|
||||
ASSERT_TRUE(authResult != nullptr);
|
||||
|
||||
int32_t ret = FlushToken(authResult);
|
||||
EXPECT_EQ(ret, ATTEST_OK);
|
||||
|
||||
uint8_t authResultCode = TDD_AUTH_RESULT;
|
||||
AttestWriteAuthResultCode((char*)&authResultCode, 1);
|
||||
AttestResultInfo attestResultInfo = { .softwareResultDetail = {-2, -2, -2, -2, -2} };
|
||||
attestResultInfo.ticket = NULL;
|
||||
ret = EntryGetAttestStatus(&attestResultInfo);
|
||||
EXPECT_TRUE((ret == ATTEST_OK) && (attestResultInfo.authResult == ATTEST_OK));
|
||||
EXPECT_TRUE((attestResultInfo.ticket != nullptr));
|
||||
if (attestResultInfo.ticket == nullptr) {
|
||||
return;
|
||||
}
|
||||
EXPECT_TRUE(strcmp(attestResultInfo.ticket, ATTEST_TICKET) == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable → Regular
+24
-24
@@ -1,24 +1,24 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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 ATTEST_TDD_TEST_DATA_TRANSFER_H
|
||||
#define ATTEST_TDD_TEST_DATA_TRANSFER_H
|
||||
#define ATTEST_MAX_TLS_LEN (10240)
|
||||
#define ATTEST_DECIMAL (10)
|
||||
#define ATTEST_ZERO_CHAR '0'
|
||||
#define ATTEST_ASCII_TO_STRING_SIZE (4)
|
||||
int32_t AttestSeriaToBinary(const char* input, uint8_t** outputBuff, size_t len);
|
||||
int32_t AttestBinaryToSerial(const uint8_t* input, int32_t inputLen,
|
||||
uint8_t** outputBuff, int32_t* outputLen);
|
||||
#endif
|
||||
/*
|
||||
* Copyright (C) 2023 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 ATTEST_TDD_TEST_DATA_TRANSFER_H
|
||||
#define ATTEST_TDD_TEST_DATA_TRANSFER_H
|
||||
#define ATTEST_MAX_TLS_LEN (10240)
|
||||
#define ATTEST_DECIMAL (10)
|
||||
#define ATTEST_ZERO_CHAR '0'
|
||||
#define ATTEST_ASCII_TO_STRING_SIZE (4)
|
||||
int32_t AttestSeriaToBinary(const char* input, uint8_t** buf, size_t len);
|
||||
int32_t AttestBinaryToSerial(const uint8_t* input, int32_t inputLen,
|
||||
uint8_t** outputBuff, int32_t* outputLen);
|
||||
#endif
|
||||
Executable → Regular
+20
-20
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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 ATTEST_TDD_MOCK_CONFIG_H
|
||||
#define ATTEST_TDD_MOCK_CONFIG_H
|
||||
|
||||
extern int32_t g_netType;
|
||||
|
||||
#endif
|
||||
/*
|
||||
* Copyright (C) 2023 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 ATTEST_TDD_MOCK_CONFIG_H
|
||||
#define ATTEST_TDD_MOCK_CONFIG_H
|
||||
|
||||
extern int32_t g_netType;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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 ATTEST_TDD_MOCK_HAL_H
|
||||
#define ATTEST_TDD_MOCK_HAL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
void AttestSetMockReadTokenRet(int value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define ATTEST_MOCK_HAL_MANU_KEY "1234567890abcdef1234567890abcdef1234567890abcdef\
|
||||
1234567890abcdef1234567890abcdef1234567890abcdef"
|
||||
#define ATTEST_MOCK_HAL_MANU_KEY_LEN 96
|
||||
|
||||
#define ATTEST_MOCK_HAL_PRO_ID "OH00Test"
|
||||
#define ATTEST_MOCK_HAL_PRO_ID_LEN 8
|
||||
|
||||
#define ATTEST_MOCK_HAL_PRO_KEY "test"
|
||||
|
||||
// tokenDecrypted "1Attest+-3Token*4Value/5=Test1e1"
|
||||
#define ATTEST_FIRST_TOKENID "e10oVXrrR8Ra9LHXuorJ8PrwwWn/RUYinPiUbFAkA0ucJA1+IUhZ5GNsacn5vnWo"
|
||||
#define ATTEST_FIRST_TOKEVALUE "e10oVXrrR8Ra9LHXuorJ8PrwwWn/RUYinPiUbFAkA0ucJA1+IUhZ5GNsacn5vnWo"
|
||||
#define ATTEST_FIRST_SALT "Sa/lt+123Te-stX="
|
||||
#define ATTEST_FIRST_VERSION "1000"
|
||||
|
||||
#define ATTEST_CASE_RESET 1
|
||||
#define ATTEST_RESET_CHAP "39a9d04d41617162893c3312ceb030acac8d8bd0cc9fcebcab5402a43891341d"
|
||||
#define ATTEST_RESET_CHAP_TIME 1234567890
|
||||
#define ATTEST_RESET_GEN_TOKEN "ldV+D/FnxYLwL3myrVLXmLTvKi92WTGQgPAk5r6KAcg="
|
||||
// tokenDecrypted "QZYbv4NdQ1oPy9zCsh2RjOpleFNd6DDA"
|
||||
#define ATTEST_RESET_GEN_PRODUCT_TOKEN "J9gNiIq3cjhWYv7rMrbEkFzHeEh3Hl9561+Taqdv7gY="
|
||||
// tokenDecrypted "AKXOFdCBwi3sHQy+YYEYM7U+WqZE1B5W"
|
||||
#define ATTEST_RESET_GEN_ONLINE_TOKEN "n2wSEwmXnYWEsSqN4yngtnt1HGO5NqS/nhj6F2DG0js="
|
||||
#define ATTEST_RESET_GEN_ONLINE_TOKEN_ID "f1feb9b7-bde2-0ee7-3089-49277d648666"
|
||||
|
||||
#define ATTEST_CASE_AUTH 2
|
||||
#define ATTEST_AUTH_EXPECT_RESULT "{\"authStats\":\".eyJhdXRoUmVzdWx0IjowLCJhdXRoVHlwZSI6IlRPS0VOX0VO\
|
||||
QUJMRSIsImV4cGlyZVRpbWUiOjE2ODMzNzM2NzE2NzQsImtpdFBvbGljeSI6W10sInNvZnR3YXJlUmVzdWx0IjozMDAwMiwic29mdHdhcmVSZXN1bHRE\
|
||||
ZXRhaWwiOnsicGF0Y2hMZXZlbFJlc3VsdCI6MzAwMDgsInBjaWRSZXN1bHQiOjMwMDExLCJyb290SGFzaFJlc3VsdCI6MzAwMDksInZlcnNpb25JZFJlc\
|
||||
3VsdCI6MzAwMDJ9LCJ1ZGlkIjoiODFDOTQ0NTI3OUEzQTQxN0Q0MTU5RkRGQzYyNjkxQkM4REEwMDJFODQ2M0M3MEQyM0FCNENCRjRERjk4MjYxQy\
|
||||
IsInZlcnNpb25JZCI6ImRlZmF1bHQvaHVhLXdlaS9rZW1pbi9kZWZhdWx0L09wZW5IYXJtb255LTQuMC4zLjIoQ2FuYXJ5MSkvb2hvcy9tYXgvMTAv\
|
||||
T3Blbkhhcm1vbnkgMi4zIGJldGEvZGVidWcifQ.\",\
|
||||
\"errcode\":0,\
|
||||
\"ticket\":\"svnR0unsciaFi7S4hcpBa/LCSiYwNSt6\",\
|
||||
\"token\":\"yh9te54pfTb91CrSqpD5fQsVBA/etKNb\",\
|
||||
\"uuid\":\"156dcff8-0ab0-4521-ac8f-ba682e6ca5a0\"\
|
||||
}3"
|
||||
#define ATTEST_AUTH_CHAP "a81441e3c0d8d6a78907fa0888f9241be9591c4d6b7a533318b010fb2c3d9b80"
|
||||
#define ATTEST_AUTH_CHAP_TIME 1234567890
|
||||
#define ATTEST_AUTH_GEN_TOKEN "hVWBm7/Rspndlt9jou8+dmJ2LFiToesDeFV4+Qrjs2A="
|
||||
// product token
|
||||
#define ATTEST_AUTH_GEN_PRODUCT_TOKEN "W8QPcxhymyPI5T/43Jh9JpOz3R6LdAqxTiWTFvHH0xY="
|
||||
// tokenDecrypted "AKXOFdCBwi3sHQy+YYEYM7U+WqZE1B5W"
|
||||
#define ATTEST_AUTH_GEN_ONLINE_TOKEN "sQW7UN8eUGOuWRYvryvoLEL+4LfDOxVUniJy2kkjt/U="
|
||||
|
||||
#define ATTEST_CASE_ACTIVE 3
|
||||
#define ATTEST_ACTIVE_CHAP "abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789"
|
||||
#define ATTEST_ACTIVE_CHAP_TIME 1234567890
|
||||
#define ATTEST_ACTIVE_GEN_TOKEN "NwccOBLvwgb5+Far1tj+zGcitRg8LAYafZn2lu4UiGE="
|
||||
// product token
|
||||
#define ATTEST_ACTIVE_GEN_PRODUCT_TOKEN "acQK/fx9oYVuLyk04MITltw8xLegbPiBf3bqtLkhVDc="
|
||||
// tokenDecrypted "AKXOFdCBwi3sHQy+YYEYM7U+WqZE1B5W"
|
||||
#define ATTEST_ACTIVE_GEN_ONLINE_TOKEN "v7kYS5P+JM2uWHLrIAVHIwckm8pyfInPHx1SHugPJe0="
|
||||
|
||||
#define ATTEST_MOCK_HAL_TICKET "svnR0unsciaFi7S4hcpBa/LCSiYwNSt6"
|
||||
#define ATTEST_MOCK_HAL_TICKET_LEN 32
|
||||
|
||||
#define ATTEST_MOCK_HAL_STATUS ".eyJhdXRoUmVzdWx0IjowLCJhdXRoVHlwZSI6IlRPS0VOX0VOQUJMRSI\
|
||||
sImV4cGlyZVRpbWUiOjE2ODMzNzM2NzE2NzQsImtpdFBvbGljeSI6W10sInNvZnR3YXJlUmVzdWx0IjozMDAwMiwic29mdHdhcmVSZXN1bHREZXRh\
|
||||
aWwiOnsicGF0Y2hMZXZlbFJlc3VsdCI6MzAwMDgsInBjaWRSZXN1bHQiOjMwMDExLCJyb290SGFzaFJlc3VsdCI6MzAwMDksInZlcnNpb25JZFJlc\
|
||||
3VsdCI6MzAwMDJ9LCJ1ZGlkIjoiODFDOTQ0NTI3OUEzQTQxN0Q0MTU5RkRGQzYyNjkxQkM4REEwMDJFODQ2M0M3MEQyM0FCNENCRjRERjk4MjYxQy\
|
||||
IsInZlcnNpb25JZCI6ImRlZmF1bHQvaHVhLXdlaS9rZW1pbi9kZWZhdWx0L09wZW5IYXJtb255LTQuMC4zLjIoQ2FuYXJ5MSkvb2hvcy9tYXgvMTAv\
|
||||
T3Blbkhhcm1vbnkgMi4zIGJldGEvZGVidWcifQ."
|
||||
#define ATTEST_MOCK_HAL_STATUS_LEN 548
|
||||
|
||||
#define ATTEST_HARDWARE_RESULT 0
|
||||
#define ATTEST_AUTH_TYPE "TOKEN_ENABLE"
|
||||
#define ATTEST_EXPIRE_TIME 1683373671674
|
||||
#define ATTEST_VERSION_ID "default/hua-wei/kemin/default/OpenHarmony-4.0.3.2(Canary1)/ohos/max/10\
|
||||
/OpenHarmony 2.3 beta/debug"
|
||||
#define ATTEST_SOFTWARE_RESULT 30002
|
||||
|
||||
#define ATTEST_MOCK_HAL_NETWORK_CONFIG_CORRECT "{\"serverInfo\":[\"testserver:443\"]}"
|
||||
#define ATTEST_MOCK_HAL_NETWORK_CONFIG_INCORRECT "{\"serverInfo\":\"testserver:443\"}"
|
||||
#define ATTEST_MOCK_HAL_NETWORK_CONFIG_LEN 256
|
||||
#define ATTEST_MOCK_HAL_NETWORK_RESULT "testserver"
|
||||
|
||||
#define ATTEST_MOCK_HAL_NETWORK_CONFIG_OPTION_CORRECT 1
|
||||
#define ATTEST_MOCK_HAL_NETWORK_CONFIG_OPTION_INCORRECT 2
|
||||
|
||||
#define ATTEST_RESULT_CODE 0
|
||||
#define ATTEST_RESULT_CODE_LEN 1
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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 ATTEST_TDD_MOCK_PROPERTY_H
|
||||
#define ATTEST_TDD_MOCK_PROPERTY_H
|
||||
|
||||
#define ATTEST_MOCK_PROPERTY_VERSIONID "default/mock-manufacture/mock-brand/default\
|
||||
/OpenHarmony-4.0.3.2(Canary1)/mock-model/max/10/OpenHarmony 2.3 beta/debug"
|
||||
#define ATTEST_MOCK_PROPERTY_HASH "abb"
|
||||
#define ATTEST_MOCK_PROPERTY_SOFTWARE_VERSION "mock 1.2.3.4"
|
||||
#define ATTEST_MOCK_PROPERTY_MANU "mock-manufacture"
|
||||
#define ATTEST_MOCK_PROPERTY_MODEL "mock-model"
|
||||
#define ATTEST_MOCK_PROPERTY_BRAND "mock-brand"
|
||||
#define ATTEST_MOCK_PROPERTY_PATCH "1234-02-29"
|
||||
#define ATTEST_MOCK_PROPERTY_UDID "a6e82fac8dd78484fb0185e1428b40eab8214e04de9e26995feb39333810d161"
|
||||
#define ATTEST_MOCK_PROPERTY_SERIAL "MOCK123456789"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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 ATTEST_TDD_TEST_H
|
||||
#define ATTEST_TDD_TEST_H
|
||||
#include "attest_utils_list.h"
|
||||
|
||||
extern List g_attestNetworkList;
|
||||
|
||||
#endif
|
||||
+134
-113
@@ -1,113 +1,134 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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 <stdbool.h>
|
||||
#include <securec.h>
|
||||
#include "attest_utils.h"
|
||||
#include "attest_utils_log.h"
|
||||
#include "attest_tdd_data_transfer.h"
|
||||
|
||||
static size_t AttestGetMallocLen(const char* input)
|
||||
{
|
||||
size_t totalFlag = 0;
|
||||
char *indexInput = (char *)input;
|
||||
while (*indexInput != '\0') {
|
||||
if (*indexInput == ',') {
|
||||
totalFlag++;
|
||||
}
|
||||
indexInput++;
|
||||
}
|
||||
size_t totalByte = totalFlag + 1;
|
||||
size_t charLen = sizeof(unsigned char);
|
||||
size_t mallocLen = charLen * totalByte + 1;
|
||||
return mallocLen;
|
||||
}
|
||||
|
||||
int32_t AttestSeriaToBinary(const char* input, uint8_t** outputBuff, size_t len)
|
||||
{
|
||||
if (outputBuff == NULL || *outputBuff == NULL) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
size_t mollocLen = AttestGetMallocLen(input);
|
||||
if (mollocLen > ATTEST_MAX_TLS_LEN) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
uint8_t *temp = (uint8_t *)malloc(mollocLen);
|
||||
if (temp == NULL) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
memset_s(temp, mollocLen, 0, mollocLen);
|
||||
|
||||
char *indexInput = (char *)input;
|
||||
unsigned char *indexTemp = (unsigned char*)temp;
|
||||
unsigned char total = 0;
|
||||
while (true) {
|
||||
if ((*indexInput == ',') || (*indexInput == '\0')) {
|
||||
*indexTemp++ = total;
|
||||
total = 0;
|
||||
} else {
|
||||
total = total * ATTEST_DECIMAL + (*indexInput - ATTEST_ZERO_CHAR);
|
||||
}
|
||||
if (*indexInput == '\0') {
|
||||
break;
|
||||
}
|
||||
indexInput++;
|
||||
}
|
||||
if (memcpy_s(*outputBuff, len, temp, len) != 0) {
|
||||
free(temp);
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
free(temp);
|
||||
return ATTEST_OK;
|
||||
}
|
||||
|
||||
int32_t AttestBinaryToSerial(const uint8_t* input, int32_t inputLen,
|
||||
uint8_t** outputBuff, int32_t* outputLen)
|
||||
{
|
||||
if (input == NULL || outputBuff == NULL || outputLen == NULL) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
int32_t outputSize = (inputLen * ATTEST_ASCII_TO_STRING_SIZE) + sizeof(ATTEST_ZERO_CHAR) + 1;
|
||||
char* tempBuf = (char *)malloc(outputSize);
|
||||
if (tempBuf == NULL) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
memset_s(tempBuf, outputSize, 0, outputSize);
|
||||
|
||||
int32_t ret = ATTEST_OK;
|
||||
int32_t offsetLength = 0;
|
||||
char* tempBufPtr = tempBuf;
|
||||
for (int32_t i = 0; i < inputLen; i++) {
|
||||
if (sprintf_s(tempBufPtr, outputSize - offsetLength, "%u", input[i]) <= 0) {
|
||||
ret = ATTEST_ERR;
|
||||
break;
|
||||
}
|
||||
for (; *tempBufPtr != '\0'; tempBufPtr++) {
|
||||
offsetLength++;
|
||||
}
|
||||
*tempBufPtr = ',';
|
||||
offsetLength++;
|
||||
tempBufPtr++;
|
||||
}
|
||||
if (ret != ATTEST_OK) {
|
||||
free(tempBuf);
|
||||
tempBuf = NULL;
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
*tempBufPtr = ATTEST_ZERO_CHAR;
|
||||
|
||||
*outputBuff = (uint8_t*)tempBuf;
|
||||
*outputLen = outputSize;
|
||||
return ATTEST_OK;
|
||||
}
|
||||
/*
|
||||
* Copyright (C) 2023 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 <pthread.h>
|
||||
#include <ctype.h>
|
||||
#include <securec.h>
|
||||
#include "attest_utils.h"
|
||||
#include "attest_utils_log.h"
|
||||
#include "attest_tdd_data_transfer.h"
|
||||
|
||||
#define ATTEST_LEAST_MALLOC_LEN 2
|
||||
|
||||
static size_t AttestGetMallocLen(const char* input)
|
||||
{
|
||||
size_t totalFlag = 0;
|
||||
for (size_t inputIndex = 0; inputIndex < strlen(input); inputIndex++) {
|
||||
if (*(input + inputIndex) == '\0') {
|
||||
break;
|
||||
}
|
||||
|
||||
if (*(input + inputIndex) == ',') {
|
||||
totalFlag++;
|
||||
}
|
||||
|
||||
if (totalFlag >= MAX_ATTEST_MALLOC_BUFF_SIZE) {
|
||||
totalFlag = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
size_t totalByte = totalFlag + 1;
|
||||
size_t charLen = sizeof(unsigned char);
|
||||
size_t mallocLen = charLen * totalByte + 1;
|
||||
return mallocLen;
|
||||
}
|
||||
|
||||
int32_t AttestSeriaToBinary(const char* input, uint8_t** buf, size_t len)
|
||||
{
|
||||
if (buf == NULL || *buf == NULL) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
size_t mollocLen = AttestGetMallocLen(input);
|
||||
if (mollocLen <= ATTEST_LEAST_MALLOC_LEN || mollocLen > ATTEST_MAX_TLS_LEN) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
uint8_t *temp = (uint8_t *)malloc(mollocLen);
|
||||
if (temp == NULL) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
memset_s(temp, mollocLen, 0, mollocLen);
|
||||
|
||||
char *indexInput = (char *)input;
|
||||
size_t inputLen = strlen(input);
|
||||
size_t tempLen = 0;
|
||||
unsigned char *indexTemp = (unsigned char*)temp;
|
||||
unsigned char total = 0;
|
||||
int32_t ret = ATTEST_OK;
|
||||
while ((tempLen <= inputLen) && (*indexInput != '\0')) {
|
||||
if (*indexInput == ',') {
|
||||
*indexTemp++ = total;
|
||||
total = 0;
|
||||
} else if (isdigit(*indexInput)) {
|
||||
total = total * ATTEST_DECIMAL + (*indexInput - ATTEST_ZERO_CHAR);
|
||||
} else {
|
||||
ret = ATTEST_ERR;
|
||||
break;
|
||||
}
|
||||
tempLen++;
|
||||
indexInput++;
|
||||
}
|
||||
if (ret != ATTEST_OK) {
|
||||
free(temp);
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
if (memcpy_s(*buf, len, temp, len) != 0) {
|
||||
free(temp);
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
free(temp);
|
||||
return ATTEST_OK;
|
||||
}
|
||||
|
||||
int32_t AttestBinaryToSerial(const uint8_t* input, int32_t inputLen,
|
||||
uint8_t** outputBuff, int32_t* outputLen)
|
||||
{
|
||||
if (input == NULL || outputBuff == NULL || outputLen == NULL) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
int32_t outputSize = (inputLen * ATTEST_ASCII_TO_STRING_SIZE) + sizeof(ATTEST_ZERO_CHAR) + 1;
|
||||
char* tempBuf = (char *)malloc(outputSize);
|
||||
if (tempBuf == NULL) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
memset_s(tempBuf, outputSize, 0, outputSize);
|
||||
|
||||
int32_t ret = ATTEST_OK;
|
||||
int32_t offsetLength = 0;
|
||||
char* tempBufPtr = tempBuf;
|
||||
for (int32_t i = 0; i < inputLen; i++) {
|
||||
if (sprintf_s(tempBufPtr, outputSize - offsetLength, "%u", input[i]) <= 0) {
|
||||
ret = ATTEST_ERR;
|
||||
break;
|
||||
}
|
||||
for (; *tempBufPtr != '\0'; tempBufPtr++) {
|
||||
offsetLength++;
|
||||
}
|
||||
*tempBufPtr = ',';
|
||||
offsetLength++;
|
||||
tempBufPtr++;
|
||||
}
|
||||
if (ret != ATTEST_OK) {
|
||||
free(tempBuf);
|
||||
tempBuf = NULL;
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
*tempBufPtr = ATTEST_ZERO_CHAR;
|
||||
|
||||
*outputBuff = (uint8_t*)tempBuf;
|
||||
*outputLen = outputSize;
|
||||
return ATTEST_OK;
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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 <pthread.h>
|
||||
#include <securec.h>
|
||||
#include <stdbool.h>
|
||||
#include "attest_type.h"
|
||||
#include "attest_tdd_test.h"
|
||||
#include "attest_tdd_mock_hal.h"
|
||||
#include "attest_utils.h"
|
||||
#include "attest_utils_log.h"
|
||||
|
||||
static int g_readTokenRet = ATTEST_OK;
|
||||
|
||||
void AttestSetMockReadTokenRet(int value)
|
||||
{
|
||||
g_readTokenRet = value;
|
||||
}
|
||||
|
||||
int32_t AttestGetManufacturekey(uint8_t manufacturekey[], uint32_t len)
|
||||
{
|
||||
return HEXStringToAscii((const char *)ATTEST_MOCK_HAL_MANU_KEY, ATTEST_MOCK_HAL_MANU_KEY_LEN,\
|
||||
(char*)manufacturekey, len);
|
||||
}
|
||||
|
||||
int32_t AttestGetProductId(uint8_t productId[], uint32_t len)
|
||||
{
|
||||
return memcpy_s(productId, len, ATTEST_MOCK_HAL_PRO_ID, ATTEST_MOCK_HAL_PRO_ID_LEN);
|
||||
}
|
||||
|
||||
int32_t AttestGetProductKey(uint8_t productKey[], uint32_t len)
|
||||
{
|
||||
return memcpy_s(productKey, len, ATTEST_MOCK_HAL_PRO_KEY, strlen(ATTEST_MOCK_HAL_PRO_KEY));
|
||||
}
|
||||
|
||||
int32_t AttestWriteToken(TokenInfo* tokenInfo)
|
||||
{
|
||||
(void)tokenInfo;
|
||||
return ATTEST_OK;
|
||||
}
|
||||
|
||||
int32_t AttestReadToken(TokenInfo* tokenInfo)
|
||||
{
|
||||
if (tokenInfo == NULL) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
|
||||
memcpy_s(tokenInfo->tokenId, TOKEN_ID_ENCRYPT_LEN, ATTEST_FIRST_TOKENID, TOKEN_ID_ENCRYPT_LEN);
|
||||
memcpy_s(tokenInfo->tokenValue, TOKEN_VALUE_ENCRYPT_LEN, ATTEST_FIRST_TOKEVALUE, TOKEN_VALUE_ENCRYPT_LEN);
|
||||
memcpy_s(tokenInfo->salt, SALT_ENCRYPT_LEN, ATTEST_FIRST_SALT, SALT_ENCRYPT_LEN);
|
||||
memcpy_s(tokenInfo->version, VERSION_ENCRYPT_LEN, ATTEST_FIRST_VERSION, VERSION_ENCRYPT_LEN);
|
||||
return g_readTokenRet;
|
||||
}
|
||||
|
||||
int32_t AttestWriteTicket(const TicketInfo* ticketInfo)
|
||||
{
|
||||
(void)ticketInfo;
|
||||
return ATTEST_OK;
|
||||
}
|
||||
|
||||
int32_t AttestReadTicket(TicketInfo* ticketInfo)
|
||||
{
|
||||
(void)ticketInfo;
|
||||
return ATTEST_OK;
|
||||
}
|
||||
|
||||
int32_t WriteTicketToDevice(const char* ticket, uint8_t len)
|
||||
{
|
||||
(void)ticket;
|
||||
(void)len;
|
||||
return ATTEST_OK;
|
||||
}
|
||||
|
||||
int32_t ReadTicketFromDevice(char* ticket, uint8_t ticketLen)
|
||||
{
|
||||
int32_t ret = memcpy_s(ticket, ticketLen, ATTEST_MOCK_HAL_TICKET, ATTEST_MOCK_HAL_TICKET_LEN);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t AttestWriteAuthStatus(const char* data, uint32_t len)
|
||||
{
|
||||
(void)data;
|
||||
(void)len;
|
||||
return ATTEST_OK;
|
||||
}
|
||||
|
||||
int32_t AttestGetAuthStatusFileSize(uint32_t* len)
|
||||
{
|
||||
*len = ATTEST_MOCK_HAL_STATUS_LEN;
|
||||
return ATTEST_OK;
|
||||
}
|
||||
|
||||
int32_t AttestReadAuthStatus(char* buffer, uint32_t bufferLen)
|
||||
{
|
||||
int32_t ret = memcpy_s(buffer, bufferLen, ATTEST_MOCK_HAL_STATUS, ATTEST_MOCK_HAL_STATUS_LEN);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t AttestWriteAuthResultCode(const char* data, uint32_t len)
|
||||
{
|
||||
(void)data;
|
||||
(void)len;
|
||||
return ATTEST_OK;
|
||||
}
|
||||
|
||||
int32_t AttestReadAuthResultCode(char* buffer, uint32_t bufferLen)
|
||||
{
|
||||
int32_t ret = memcpy_s(buffer, bufferLen, ATTEST_RESULT_CODE, ATTEST_RESULT_CODE_LEN);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool AttestNetworkConfigExist(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t AttestWriteNetworkConfig(const char* buffer, uint32_t bufferLen)
|
||||
{
|
||||
(void)buffer;
|
||||
(void)bufferLen;
|
||||
return ATTEST_OK;
|
||||
}
|
||||
|
||||
int32_t AttestReadNetworkConfig(char* buffer, uint32_t bufferLen)
|
||||
{
|
||||
if (buffer == NULL) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
static int32_t status = 1;
|
||||
int32_t ret = ATTEST_ERR;
|
||||
switch (status) {
|
||||
case ATTEST_MOCK_HAL_NETWORK_CONFIG_OPTION_CORRECT:
|
||||
ret = memcpy_s(buffer, bufferLen, ATTEST_MOCK_HAL_NETWORK_CONFIG_CORRECT, ATTEST_MOCK_HAL_NETWORK_CONFIG_LEN);
|
||||
break;
|
||||
case ATTEST_MOCK_HAL_NETWORK_CONFIG_OPTION_INCORRECT:
|
||||
ret = memcpy_s(buffer, bufferLen, ATTEST_MOCK_HAL_NETWORK_CONFIG_INCORRECT, ATTEST_MOCK_HAL_NETWORK_CONFIG_LEN);
|
||||
break;
|
||||
default:
|
||||
ret = memcpy_s(buffer, bufferLen, ATTEST_MOCK_HAL_NETWORK_CONFIG_CORRECT, ATTEST_MOCK_HAL_NETWORK_CONFIG_LEN);
|
||||
break;
|
||||
}
|
||||
status++;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t AttestReadDefaultNetworkConfig(char* buffer, uint32_t bufferLen)
|
||||
{
|
||||
(void)buffer;
|
||||
(void)bufferLen;
|
||||
return ATTEST_OK;
|
||||
}
|
||||
|
||||
@@ -1,101 +1,104 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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 "securec.h"
|
||||
#include "attest_channel.h"
|
||||
#include "attest_tls.h"
|
||||
#include "attest_utils.h"
|
||||
#include "attest_utils_log.h"
|
||||
#include "attest_tdd_mock_config.h"
|
||||
#include "attest_tdd_data_transfer.h"
|
||||
|
||||
int32_t g_netType = 0;
|
||||
|
||||
#define MAX_INVOKE_TIME 3
|
||||
#define MAX_NO_EXTEND_TIME 2
|
||||
#define INTERFACE_COUNT 4
|
||||
|
||||
// can't change network
|
||||
#define ATTEST_RESET_CHAP_FIRST_MSG "210,0"
|
||||
#define ATTEST_RESET_CHAP_SECOND_MSG "227,49"
|
||||
#define ATTEST_RESET_CHAP_THIRD_MSG "69,166,93,255,123,34,99,104,97,108,108,101,110,103,101,34,58,34,51,57,\
|
||||
97,57,100,48,52,100,52,49,54,49,55,49,54,50,56,57,51,99,51,51,49,50,99,101,98,48,51,48,97,99,97,99,56,100,56,\
|
||||
98,100,48,99,99,57,102,99,101,98,99,97,98,53,52,48,50,97,52,51,56,57,49,51,52,49,100,34,44,34,99,117,114,114,\
|
||||
101,110,116,84,105,109,101,34,58,49,54,56,48,55,56,49,54,55,49,50,50,54,44,34,101,114,114,99,111,100,101,34,58,\
|
||||
48,44,34,115,101,114,118,101,114,73,110,102,111,34,58,123,34,97,99,116,105,118,101,83,105,116,101,34,58,34,119,\
|
||||
105,115,101,100,101,118,105,99,101,45,108,105,116,101,45,100,114,99,110,46,111,112,101,110,104,97,114,109,111,\
|
||||
110,121,46,99,110,34,44,34,115,116,97,110,100,98,121,83,105,116,101,34,58,34,119,105,115,101,100,101,118,105,99,\
|
||||
101,45,108,105,116,101,45,100,114,99,110,46,111,112,101,110,104,97,114,109,111,110,121,46,99,110,34,125,125,0"
|
||||
|
||||
#define ATTEST_REST_ERROR_FIRST_MSG "210,0"
|
||||
#define ATTEST_REST_ERROR_SECOND_MSG "5,49"
|
||||
#define ATTEST_REST_ERROR_THIRD_MSG "69,128,194,255,123,34,101,114,114,99,111,100,101,34,58,49,53,48,48,51,125,0"
|
||||
|
||||
#define ATTEST_AUTH_FIRST_MSG "226,0"
|
||||
#define ATTEST_AUTH_SECOND_MSG "1,185,54"
|
||||
#define ATTEST_AUTH_THIRD_MSG "69,184,100,255,123,34,99,104,97,108,108,101,110,103,101,34,58,34,97,56,49,52,\
|
||||
52,49,101,51,99,48,100,56,100,54,97,55,56,57,48,55,102,97,48,56,56,56,102,57,50,52,49,98,101,57,53,57,49,99,52,100,54,\
|
||||
98,55,97,53,51,51,51,49,56,98,48,49,48,102,98,50,99,51,100,57,98,56,48,34,44,34,99,117,114,114,101,110,116,84,105,109,\
|
||||
101,34,58,49,54,56,48,55,56,49,54,55,49,52,53,53,44,34,101,114,114,99,111,100,101,34,58,48,125,108"
|
||||
|
||||
#define ATTEST_ACTIVE_FIRST_MSG "210,0"
|
||||
#define ATTEST_ACTIVE_SECOND_MSG "1,49"
|
||||
#define ATTEST_ACTIVE_THIRD_MSG "69,254,246,255,123,34,101,114,114,99,111,100,101,34,58,48,125,0"
|
||||
|
||||
static const char *mockTlsData[MAX_INVOKE_TIME][INTERFACE_COUNT] = {
|
||||
{ATTEST_RESET_CHAP_FIRST_MSG, ATTEST_REST_ERROR_FIRST_MSG, ATTEST_ACTIVE_FIRST_MSG, ATTEST_AUTH_FIRST_MSG},
|
||||
{ATTEST_RESET_CHAP_SECOND_MSG, ATTEST_REST_ERROR_SECOND_MSG, ATTEST_ACTIVE_SECOND_MSG, ATTEST_AUTH_SECOND_MSG},
|
||||
{ATTEST_RESET_CHAP_THIRD_MSG, ATTEST_REST_ERROR_THIRD_MSG, ATTEST_ACTIVE_THIRD_MSG, ATTEST_AUTH_THIRD_MSG}
|
||||
};
|
||||
bool isHasExtend[4] = {true, true, true, true};
|
||||
int g_cout = 0;
|
||||
|
||||
int32_t TLSConnect(TLSSession* session)
|
||||
{
|
||||
ATTEST_LOG_DEBUG("[TLSConnect mock] Begin.");
|
||||
if (session == NULL) {
|
||||
return ERR_NET_INVALID_ARG;
|
||||
}
|
||||
return ATTEST_OK;
|
||||
}
|
||||
|
||||
int32_t TLSWrite(const TLSSession* session, const uint8_t* buf, size_t len)
|
||||
{
|
||||
(void)session;
|
||||
(void)buf;
|
||||
(void)len;
|
||||
return ATTEST_OK;
|
||||
}
|
||||
|
||||
int32_t TLSRead(const TLSSession* session, uint8_t* buf, size_t len)
|
||||
{
|
||||
(void)session;
|
||||
(void)len;
|
||||
if (g_cout > MAX_INVOKE_TIME || (g_netType < 0 || g_netType > INTERFACE_COUNT - 1)) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
int32_t ret = AttestSeriaToBinary(mockTlsData[g_cout][g_netType], &buf, len);
|
||||
g_cout++;
|
||||
int32_t maxInvokeTime = isHasExtend[g_netType] ? MAX_INVOKE_TIME : MAX_NO_EXTEND_TIME;
|
||||
if (g_cout == maxInvokeTime) {
|
||||
g_cout = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t TLSClose(TLSSession* session)
|
||||
{
|
||||
(void)session;
|
||||
return ATTEST_OK;
|
||||
}
|
||||
/*
|
||||
* Copyright (C) 2023 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 <pthread.h>
|
||||
#include "securec.h"
|
||||
#include "attest_channel.h"
|
||||
#include "attest_tls.h"
|
||||
#include "attest_utils.h"
|
||||
#include "attest_utils_log.h"
|
||||
#include "attest_tdd_mock_config.h"
|
||||
#include "attest_tdd_data_transfer.h"
|
||||
|
||||
int32_t g_netType = 0;
|
||||
|
||||
#define MAX_INVOKE_TIME 3
|
||||
#define MAX_NO_EXTEND_TIME 2
|
||||
#define INTERFACE_COUNT 4
|
||||
|
||||
// can't change network
|
||||
#define ATTEST_RESET_CHAP_FIRST_MSG "210,0"
|
||||
#define ATTEST_RESET_CHAP_SECOND_MSG "227,49"
|
||||
#define ATTEST_RESET_CHAP_THIRD_MSG "69,166,93,255,123,34,99,104,97,108,108,101,110,103,101,34,58,34,51,57,\
|
||||
97,57,100,48,52,100,52,49,54,49,55,49,54,50,56,57,51,99,51,51,49,50,99,101,98,48,51,48,97,99,97,99,56,100,56,\
|
||||
98,100,48,99,99,57,102,99,101,98,99,97,98,53,52,48,50,97,52,51,56,57,49,51,52,49,100,34,44,34,99,117,114,114,\
|
||||
101,110,116,84,105,109,101,34,58,49,54,56,48,55,56,49,54,55,49,50,50,54,44,34,101,114,114,99,111,100,101,34,58,\
|
||||
48,44,34,115,101,114,118,101,114,73,110,102,111,34,58,123,34,97,99,116,105,118,101,83,105,116,101,34,58,34,119,\
|
||||
105,115,101,100,101,118,105,99,101,45,108,105,116,101,45,100,114,99,110,46,111,112,101,110,104,97,114,109,111,\
|
||||
110,121,46,99,110,34,44,34,115,116,97,110,100,98,121,83,105,116,101,34,58,34,119,105,115,101,100,101,118,105,99,\
|
||||
101,45,108,105,116,101,45,100,114,99,110,46,111,112,101,110,104,97,114,109,111,110,121,46,99,110,34,125,125,0"
|
||||
|
||||
#define ATTEST_REST_ERROR_FIRST_MSG "210,0"
|
||||
#define ATTEST_REST_ERROR_SECOND_MSG "5,49"
|
||||
#define ATTEST_REST_ERROR_THIRD_MSG "69,128,194,255,123,34,101,114,114,99,111,100,101,34,58,49,53,48,48,51,125,0"
|
||||
|
||||
#define ATTEST_AUTH_FIRST_MSG "226,0"
|
||||
#define ATTEST_AUTH_SECOND_MSG "1,185,54"
|
||||
#define ATTEST_AUTH_THIRD_MSG "69,184,100,255,123,34,99,104,97,108,108,101,110,103,101,34,58,34,97,56,49,52,\
|
||||
52,49,101,51,99,48,100,56,100,54,97,55,56,57,48,55,102,97,48,56,56,56,102,57,50,52,49,98,101,57,53,57,49,99,52,100,54,\
|
||||
98,55,97,53,51,51,51,49,56,98,48,49,48,102,98,50,99,51,100,57,98,56,48,34,44,34,99,117,114,114,101,110,116,84,105,109,\
|
||||
101,34,58,49,54,56,48,55,56,49,54,55,49,52,53,53,44,34,101,114,114,99,111,100,101,34,58,48,125,108"
|
||||
|
||||
#define ATTEST_ACTIVE_FIRST_MSG "210,0"
|
||||
#define ATTEST_ACTIVE_SECOND_MSG "1,49"
|
||||
#define ATTEST_ACTIVE_THIRD_MSG "69,254,246,255,123,34,101,114,114,99,111,100,101,34,58,48,125,0"
|
||||
|
||||
static const char *mockTlsData[MAX_INVOKE_TIME][INTERFACE_COUNT] = {
|
||||
{ATTEST_RESET_CHAP_FIRST_MSG, ATTEST_REST_ERROR_FIRST_MSG, ATTEST_ACTIVE_FIRST_MSG, ATTEST_AUTH_FIRST_MSG},
|
||||
{ATTEST_RESET_CHAP_SECOND_MSG, ATTEST_REST_ERROR_SECOND_MSG, ATTEST_ACTIVE_SECOND_MSG, ATTEST_AUTH_SECOND_MSG},
|
||||
{ATTEST_RESET_CHAP_THIRD_MSG, ATTEST_REST_ERROR_THIRD_MSG, ATTEST_ACTIVE_THIRD_MSG, ATTEST_AUTH_THIRD_MSG}
|
||||
};
|
||||
bool isHasExtend[4] = {true, true, true, true};
|
||||
int g_cout = 0;
|
||||
|
||||
int32_t TLSConnect(TLSSession* session)
|
||||
{
|
||||
ATTEST_LOG_INFO("[TLSConnect mock] Begin.");
|
||||
if (session == NULL) {
|
||||
return ERR_NET_INVALID_ARG;
|
||||
}
|
||||
return ATTEST_OK;
|
||||
}
|
||||
|
||||
int32_t TLSWrite(const TLSSession* session, const uint8_t* buf, size_t len)
|
||||
{
|
||||
(void)session;
|
||||
(void)buf;
|
||||
(void)len;
|
||||
return ATTEST_OK;
|
||||
}
|
||||
|
||||
int32_t TLSRead(const TLSSession* session, uint8_t* buf, size_t len)
|
||||
{
|
||||
(void)session;
|
||||
(void)len;
|
||||
ATTEST_LOG_INFO("[TLSRead mock] g_cout:%d, g_netType:%d", g_cout, g_netType);
|
||||
if (g_cout > MAX_INVOKE_TIME || (g_netType < 0 || g_netType > INTERFACE_COUNT - 1)) {
|
||||
return ATTEST_ERR;
|
||||
}
|
||||
int32_t ret = AttestSeriaToBinary(mockTlsData[g_cout][g_netType], &buf, len);
|
||||
g_cout++;
|
||||
int32_t maxInvokeTime = isHasExtend[g_netType] ? MAX_INVOKE_TIME : MAX_NO_EXTEND_TIME;
|
||||
if (g_cout == maxInvokeTime) {
|
||||
g_cout = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t TLSClose(TLSSession* session)
|
||||
{
|
||||
(void)session;
|
||||
return ATTEST_OK;
|
||||
}
|
||||
+65
-70
@@ -1,70 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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 "attest_utils.h"
|
||||
#include "attest_adapter_os.h"
|
||||
|
||||
const char* ATTEST_NET_VERSIONID = "default/hua-wei/kemin/default/OpenHarmony-4.0.3.2(Canary1)/ohos/max/10\
|
||||
/OpenHarmony 2.3 beta/debug";
|
||||
const char* ATTEST_BUILD_ROOT_HASH = "test666";
|
||||
const char* ATTEST_SOFTWARE_VERSION = "OpenHarmony 4.0.3.2";
|
||||
const char* ATTEST_PRODUCT_MODEL = "ohos";
|
||||
const char* ATTEST_BRAND = "kemin";
|
||||
const char* ATTEST_SECURITY_PATCH = "2022-09-01";
|
||||
const char* ATTEST_UDID = "81C9445279A3A417D4159FDFC62691BC8DA002E8463C70D23AB4CBF4DF98261C";
|
||||
|
||||
char* AttestGetVersionId(void)
|
||||
{
|
||||
return AttestStrdup(ATTEST_NET_VERSIONID);
|
||||
}
|
||||
|
||||
char* AttestGetBuildRootHash(void)
|
||||
{
|
||||
return AttestStrdup(ATTEST_BUILD_ROOT_HASH);
|
||||
}
|
||||
|
||||
char* AttestGetDisplayVersion(void)
|
||||
{
|
||||
return AttestStrdup(ATTEST_SOFTWARE_VERSION);
|
||||
}
|
||||
|
||||
char* AttestGetProductModel(void)
|
||||
{
|
||||
return AttestStrdup(ATTEST_PRODUCT_MODEL);
|
||||
}
|
||||
|
||||
char* AttestGetBrand(void)
|
||||
{
|
||||
return AttestStrdup(ATTEST_BRAND);
|
||||
}
|
||||
|
||||
char* AttestGetSecurityPatchTag(void)
|
||||
{
|
||||
return AttestStrdup(ATTEST_SECURITY_PATCH);
|
||||
}
|
||||
|
||||
char* AttestGetUdid(void)
|
||||
{
|
||||
return AttestStrdup(ATTEST_UDID);
|
||||
}
|
||||
|
||||
char* AttestGetManufacture(void)
|
||||
{
|
||||
return AttestStrdup(OsGetManufacture());
|
||||
}
|
||||
|
||||
char* AttestGetSerial(void)
|
||||
{
|
||||
return OsGetSerial();
|
||||
}
|
||||
/*
|
||||
* Copyright (C) 2023 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 <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include "attest_utils.h"
|
||||
#include "attest_adapter_os.h"
|
||||
#include "attest_tdd_mock_property.h"
|
||||
|
||||
char* AttestGetVersionId(void)
|
||||
{
|
||||
return AttestStrdup(ATTEST_MOCK_PROPERTY_VERSIONID);
|
||||
}
|
||||
|
||||
char* AttestGetBuildRootHash(void)
|
||||
{
|
||||
return AttestStrdup(ATTEST_MOCK_PROPERTY_HASH);
|
||||
}
|
||||
|
||||
char* AttestGetDisplayVersion(void)
|
||||
{
|
||||
return AttestStrdup(ATTEST_MOCK_PROPERTY_SOFTWARE_VERSION);
|
||||
}
|
||||
|
||||
char* AttestGetManufacture(void)
|
||||
{
|
||||
return AttestStrdup(ATTEST_MOCK_PROPERTY_MANU);
|
||||
}
|
||||
|
||||
char* AttestGetProductModel(void)
|
||||
{
|
||||
return AttestStrdup(ATTEST_MOCK_PROPERTY_MODEL);
|
||||
}
|
||||
|
||||
char* AttestGetBrand(void)
|
||||
{
|
||||
return AttestStrdup(ATTEST_MOCK_PROPERTY_BRAND);
|
||||
}
|
||||
|
||||
char* AttestGetSecurityPatchTag(void)
|
||||
{
|
||||
return AttestStrdup(ATTEST_MOCK_PROPERTY_PATCH);
|
||||
}
|
||||
|
||||
char* AttestGetUdid(void)
|
||||
{
|
||||
return AttestStrdup(ATTEST_MOCK_PROPERTY_UDID);
|
||||
}
|
||||
|
||||
char* AttestGetSerial(void)
|
||||
{
|
||||
return AttestStrdup(ATTEST_MOCK_PROPERTY_SERIAL);
|
||||
}
|
||||
@@ -0,0 +1,636 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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 <securec.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "devattest_log.h"
|
||||
#include "attest_entry.h"
|
||||
#include "attest_result_info.h"
|
||||
#include "attest_type.h"
|
||||
#include "attest_service_active.h"
|
||||
#include "attest_service_auth.h"
|
||||
#include "attest_service_challenge.h"
|
||||
#include "attest_service_device.h"
|
||||
#include "attest_service.h"
|
||||
#include "attest_service_device.h"
|
||||
#include "attest_security_token.h"
|
||||
#include "attest_service_reset.h"
|
||||
#include "attest_network.h"
|
||||
#include "attest_adapter.h"
|
||||
#include "devattest_errno.h"
|
||||
#include "attest_utils.h"
|
||||
#include "attest_tdd_mock_property.h"
|
||||
#include "attest_tdd_mock_hal.h"
|
||||
#include "attest_tdd_test.h"
|
||||
#include "attest_tdd_mock_config.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
namespace DevAttest {
|
||||
|
||||
static const int32_t ATTEST_GET_CHANLLEGE = 0;
|
||||
static const int32_t ATTEST_RESET = 1;
|
||||
static const int32_t ATTEST_ACTIVE = 2;
|
||||
static const int32_t ATTEST_AUTH = 3;
|
||||
|
||||
static const char* ATTEST_REST_ERROR_EXPECT_RESULT = "15003";
|
||||
static const char* ATTEST_RESET_EXPECT_CHAP = "39a9d04d41617162893c3312ceb030acac8d8bd0cc9fcebcab5402a43891341d";
|
||||
|
||||
class AttestTddTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
|
||||
static void TearDownTestCase(void);
|
||||
|
||||
void SetUp();
|
||||
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void AttestTddTest::SetUpTestCase(void)
|
||||
{
|
||||
}
|
||||
|
||||
void AttestTddTest::TearDownTestCase(void)
|
||||
{
|
||||
}
|
||||
|
||||
void AttestTddTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void AttestTddTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestInitSysData001
|
||||
* @tc.desc: Test init system data.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestInitSysData001, TestSize.Level1)
|
||||
{
|
||||
int32_t ret = InitSysData();
|
||||
EXPECT_TRUE(ret == DEVATTEST_SUCCESS);
|
||||
EXPECT_STREQ(StrdupDevInfo(VERSION_ID), ATTEST_MOCK_PROPERTY_VERSIONID);
|
||||
EXPECT_STREQ(StrdupDevInfo(ROOT_HASH), ATTEST_MOCK_PROPERTY_HASH);
|
||||
EXPECT_STREQ(StrdupDevInfo(DISPLAY_VERSION), ATTEST_MOCK_PROPERTY_SOFTWARE_VERSION);
|
||||
EXPECT_STREQ(StrdupDevInfo(MANU_FACTURE), ATTEST_MOCK_PROPERTY_MANU);
|
||||
EXPECT_STREQ(StrdupDevInfo(PRODUCT_MODEL), ATTEST_MOCK_PROPERTY_MODEL);
|
||||
EXPECT_STREQ(StrdupDevInfo(BRAND), ATTEST_MOCK_PROPERTY_BRAND);
|
||||
EXPECT_STREQ(StrdupDevInfo(SECURITY_PATCH_TAG), ATTEST_MOCK_PROPERTY_PATCH);
|
||||
EXPECT_STREQ(StrdupDevInfo(UDID), ATTEST_MOCK_PROPERTY_UDID);
|
||||
// 恢复环境
|
||||
DestroySysData();
|
||||
EXPECT_TRUE(StrdupDevInfo(VERSION_ID) == NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestInitNetWork001
|
||||
* @tc.desc: Test init network, result is success.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestInitNetWork001, TestSize.Level1)
|
||||
{
|
||||
int ret = InitNetworkServerInfo();
|
||||
EXPECT_TRUE(ret == DEVATTEST_SUCCESS);
|
||||
ServerInfo* serverInfo = (ServerInfo*)g_attestNetworkList.head->data;
|
||||
EXPECT_STREQ(serverInfo->hostName, ATTEST_MOCK_HAL_NETWORK_RESULT);
|
||||
ReleaseList(&g_attestNetworkList);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestInitNetWork002
|
||||
* @tc.desc: Test init network, result is fail.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestInitNetWork002, TestSize.Level1)
|
||||
{
|
||||
int ret = InitNetworkServerInfo();
|
||||
EXPECT_TRUE(ret == DEVATTEST_FAIL);
|
||||
ReleaseList(&g_attestNetworkList);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestGetAuthStatus001
|
||||
* @tc.desc: Test get authStatus.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestGetAuthStatus001, TestSize.Level1)
|
||||
{
|
||||
int32_t ret = FlushAuthResult(ATTEST_MOCK_HAL_TICKET, ATTEST_MOCK_HAL_STATUS);
|
||||
EXPECT_TRUE((ret == DEVATTEST_SUCCESS));
|
||||
char *status = nullptr;
|
||||
ret = GetAuthStatus(&status);
|
||||
EXPECT_TRUE((ret == DEVATTEST_SUCCESS));
|
||||
EXPECT_TRUE((status != nullptr));
|
||||
if (status == nullptr) {
|
||||
return;
|
||||
}
|
||||
EXPECT_STREQ(ATTEST_MOCK_HAL_STATUS, status);
|
||||
free(status);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestDecodeAuthStatus001
|
||||
* @tc.desc: Test decode auth status.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestDecodeAuthStatus001, TestSize.Level1)
|
||||
{
|
||||
char *status = nullptr;
|
||||
int32_t ret = GetAuthStatus(&status);
|
||||
EXPECT_TRUE((ret == DEVATTEST_SUCCESS));
|
||||
AuthStatus* outStatus = CreateAuthStatus();
|
||||
EXPECT_TRUE((outStatus != nullptr));
|
||||
if (outStatus == nullptr) {
|
||||
return;
|
||||
}
|
||||
ret = DecodeAuthStatus(status, outStatus);
|
||||
EXPECT_TRUE(ret == DEVATTEST_SUCCESS);
|
||||
SoftwareResultDetail* detail = outStatus->softwareResultDetail;
|
||||
EXPECT_TRUE((outStatus->versionId != nullptr) && (outStatus->authType != nullptr) && (detail != nullptr));
|
||||
if ((outStatus->versionId == nullptr) || (outStatus->authType == nullptr) || (detail == nullptr)) {
|
||||
DestroyAuthStatus(&outStatus);
|
||||
return;
|
||||
}
|
||||
EXPECT_TRUE(outStatus->hardwareResult == ATTEST_HARDWARE_RESULT);
|
||||
EXPECT_STREQ(outStatus->authType, ATTEST_AUTH_TYPE);
|
||||
EXPECT_TRUE(outStatus->expireTime == ATTEST_EXPIRE_TIME);
|
||||
EXPECT_STREQ(outStatus->versionId, ATTEST_VERSION_ID);
|
||||
EXPECT_TRUE(outStatus->softwareResult == ATTEST_SOFTWARE_RESULT);
|
||||
DestroyAuthStatus(&outStatus);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestCheckExpireTime001
|
||||
* @tc.desc: Test check expire time.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestCheckExpireTime001, TestSize.Level1)
|
||||
{
|
||||
AuthStatus* outStatus = CreateAuthStatus();
|
||||
EXPECT_TRUE(outStatus != nullptr);
|
||||
if (outStatus == nullptr) {
|
||||
return;
|
||||
}
|
||||
outStatus->expireTime = 19673222;
|
||||
uint64_t currentTime = 19673223;
|
||||
int32_t ret = CheckExpireTime(outStatus, currentTime);
|
||||
EXPECT_TRUE(ret != DEVATTEST_SUCCESS);
|
||||
outStatus->expireTime = 19673222;
|
||||
currentTime = 19673221;
|
||||
ret = CheckExpireTime(outStatus, currentTime);
|
||||
EXPECT_TRUE(ret == DEVATTEST_SUCCESS);
|
||||
free(outStatus);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestCheckAuthResult001
|
||||
* @tc.desc: Test check auth result.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestCheckAuthResult001, TestSize.Level1)
|
||||
{
|
||||
AuthStatus* outStatus = CreateAuthStatus();
|
||||
EXPECT_TRUE(outStatus != nullptr);
|
||||
if (outStatus == nullptr) {
|
||||
return;
|
||||
}
|
||||
outStatus->hardwareResult = 1;
|
||||
outStatus->softwareResult = 0;
|
||||
int32_t ret = CheckAuthResult(outStatus);
|
||||
EXPECT_TRUE(ret != DEVATTEST_SUCCESS);
|
||||
outStatus->hardwareResult = 0;
|
||||
ret = CheckAuthResult(outStatus);
|
||||
EXPECT_TRUE(ret == DEVATTEST_SUCCESS);
|
||||
free(outStatus);
|
||||
}
|
||||
|
||||
static AuthResult *GetAuthResult()
|
||||
{
|
||||
AuthResult *authResult = CreateAuthResult();
|
||||
if (authResult == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
int32_t ret = ParseAuthResultResp(ATTEST_AUTH_EXPECT_RESULT, authResult);
|
||||
if (ret != DEVATTEST_SUCCESS) {
|
||||
DestroyAuthResult(&authResult);
|
||||
return nullptr;
|
||||
}
|
||||
return authResult;
|
||||
}
|
||||
|
||||
static DevicePacket* TddGenMsg(int input)
|
||||
{
|
||||
DevicePacket* reqMsg = nullptr;
|
||||
int32_t ret = DEVATTEST_SUCCESS;
|
||||
ChallengeResult challenge;
|
||||
do {
|
||||
if (input == ATTEST_CASE_RESET) {
|
||||
challenge.challenge = (char*)ATTEST_RESET_CHAP;
|
||||
challenge.currentTime = ATTEST_RESET_CHAP_TIME;
|
||||
ret = GenResetMsg(&challenge, &reqMsg);
|
||||
break;
|
||||
}
|
||||
if (input == ATTEST_CASE_AUTH) {
|
||||
challenge.challenge = (char*)ATTEST_AUTH_CHAP;
|
||||
challenge.currentTime = ATTEST_AUTH_CHAP_TIME;
|
||||
ret = GenAuthMsg(&challenge, &reqMsg);
|
||||
break;
|
||||
}
|
||||
if (input == ATTEST_CASE_ACTIVE) {
|
||||
challenge.challenge = (char*)ATTEST_ACTIVE_CHAP;
|
||||
challenge.currentTime = ATTEST_ACTIVE_CHAP_TIME;
|
||||
AuthResult *authResult = GetAuthResult();
|
||||
ret = GenActiveMsg(authResult, &challenge, &reqMsg);
|
||||
break;
|
||||
}
|
||||
} while (0);
|
||||
EXPECT_TRUE(ret == DEVATTEST_SUCCESS);
|
||||
if (ret != DEVATTEST_SUCCESS) {
|
||||
FREE_DEVICE_PACKET(reqMsg);
|
||||
return nullptr;
|
||||
}
|
||||
return reqMsg;
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestGenResetMsg001
|
||||
* @tc.desc: Test gen reset msg with stored token.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestGenResetMsg001, TestSize.Level1)
|
||||
{
|
||||
AttestSetMockReadTokenRet(ATTEST_OK);
|
||||
// 初始化参数
|
||||
int32_t ret = InitSysData();
|
||||
EXPECT_TRUE(ret == DEVATTEST_SUCCESS);
|
||||
|
||||
DevicePacket* reqMsg = TddGenMsg(ATTEST_CASE_RESET);
|
||||
EXPECT_TRUE((reqMsg != nullptr));
|
||||
if (reqMsg == nullptr) {
|
||||
DestroySysData();
|
||||
return;
|
||||
}
|
||||
char *outToken = reqMsg->tokenInfo.token;
|
||||
EXPECT_TRUE(outToken != nullptr);
|
||||
if (outToken == NULL) {
|
||||
FREE_DEVICE_PACKET(reqMsg);
|
||||
DestroySysData();
|
||||
return;
|
||||
}
|
||||
EXPECT_TRUE(strcmp(ATTEST_RESET_GEN_TOKEN, outToken) == 0);
|
||||
FREE_DEVICE_PACKET(reqMsg);
|
||||
// 恢复环境
|
||||
DestroySysData();
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestGenResetMsg002
|
||||
* @tc.desc: Test gen reset msg without token.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestGenResetMsg002, TestSize.Level1)
|
||||
{
|
||||
AttestSetMockReadTokenRet(TOKEN_UNPRESET);
|
||||
// 初始化参数
|
||||
int32_t ret = InitSysData();
|
||||
EXPECT_TRUE(ret == DEVATTEST_SUCCESS);
|
||||
|
||||
DevicePacket* reqMsg = TddGenMsg(ATTEST_CASE_RESET);
|
||||
EXPECT_TRUE((reqMsg != nullptr));
|
||||
if (reqMsg == nullptr) {
|
||||
DestroySysData();
|
||||
return;
|
||||
}
|
||||
char *outToken = reqMsg->tokenInfo.token;
|
||||
EXPECT_TRUE(outToken != nullptr);
|
||||
if (outToken == NULL) {
|
||||
FREE_DEVICE_PACKET(reqMsg);
|
||||
DestroySysData();
|
||||
return;
|
||||
}
|
||||
#if defined(__ATTEST_ENABLE_PRESET_TOKEN__)
|
||||
EXPECT_TRUE(strcmp(ATTEST_RESET_GEN_ONLINE_TOKEN, outToken) == 0);
|
||||
|
||||
outToken = reqMsg->tokenInfo.uuid;
|
||||
EXPECT_TRUE(outToken != nullptr);
|
||||
if (outToken == NULL) {
|
||||
FREE_DEVICE_PACKET(reqMsg);
|
||||
DestroySysData();
|
||||
return;
|
||||
}
|
||||
EXPECT_TRUE(strcmp(ATTEST_RESET_GEN_ONLINE_TOKEN_ID, outToken) == 0);
|
||||
#else
|
||||
EXPECT_TRUE(strcmp(ATTEST_RESET_GEN_PRODUCT_TOKEN, outToken) == 0);
|
||||
#endif
|
||||
FREE_DEVICE_PACKET(reqMsg);
|
||||
// 恢复环境
|
||||
DestroySysData();
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestParseResetResult001
|
||||
* @tc.desc: Test parse reset result,result is ok.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestParseResetResult001, TestSize.Level1)
|
||||
{
|
||||
string input = "{\"errcode\":0}";
|
||||
int32_t ret = ParseResetResult(input.c_str());
|
||||
EXPECT_TRUE(ret == DEVATTEST_SUCCESS);
|
||||
input = "{\"errcode\":\"-32s\"}";
|
||||
ret = ParseResetResult(input.c_str());
|
||||
EXPECT_TRUE((ret != DEVATTEST_SUCCESS));
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestGenAuthMsg001
|
||||
* @tc.desc: Test gen auth msg.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestGenAuthMsg001, TestSize.Level1)
|
||||
{
|
||||
AttestSetMockReadTokenRet(ATTEST_OK);
|
||||
// 初始化参数
|
||||
int32_t ret = InitSysData();
|
||||
EXPECT_TRUE(ret == DEVATTEST_SUCCESS);
|
||||
|
||||
DevicePacket* reqMsg = TddGenMsg(ATTEST_CASE_AUTH);
|
||||
EXPECT_TRUE((reqMsg != nullptr));
|
||||
if (reqMsg == NULL) {
|
||||
return;
|
||||
}
|
||||
char *outToken = reqMsg->tokenInfo.token;
|
||||
EXPECT_TRUE(outToken != nullptr);
|
||||
if (outToken == NULL) {
|
||||
FREE_DEVICE_PACKET(reqMsg);
|
||||
return;
|
||||
}
|
||||
EXPECT_TRUE(strcmp(outToken, ATTEST_AUTH_GEN_TOKEN) == 0);
|
||||
FREE_DEVICE_PACKET(reqMsg);
|
||||
// 恢复环境
|
||||
DestroySysData();
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestGenAuthMsg002
|
||||
* @tc.desc: Test gen auth msg without token.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestGenAuthMsg002, TestSize.Level1)
|
||||
{
|
||||
AttestSetMockReadTokenRet(TOKEN_UNPRESET);
|
||||
// 初始化参数
|
||||
int32_t ret = InitSysData();
|
||||
EXPECT_TRUE(ret == DEVATTEST_SUCCESS);
|
||||
|
||||
DevicePacket* reqMsg = TddGenMsg(ATTEST_CASE_AUTH);
|
||||
EXPECT_TRUE((reqMsg != nullptr));
|
||||
if (reqMsg == nullptr) {
|
||||
return;
|
||||
}
|
||||
char *outToken = reqMsg->tokenInfo.token;
|
||||
EXPECT_TRUE(outToken != nullptr);
|
||||
if (outToken == NULL) {
|
||||
FREE_DEVICE_PACKET(reqMsg);
|
||||
return;
|
||||
}
|
||||
#if defined(__ATTEST_ENABLE_PRESET_TOKEN__)
|
||||
EXPECT_TRUE(strcmp(ATTEST_AUTH_GEN_ONLINE_TOKEN, outToken) == 0);
|
||||
#else
|
||||
EXPECT_TRUE(strcmp(ATTEST_AUTH_GEN_PRODUCT_TOKEN, outToken) == 0);
|
||||
#endif
|
||||
FREE_DEVICE_PACKET(reqMsg);
|
||||
// 恢复环境
|
||||
DestroySysData();
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestParseAuthResultResp001
|
||||
* @tc.desc: Test parse auth result resp.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestParseAuthResultResp001, TestSize.Level1)
|
||||
{
|
||||
AuthResult *authResult = GetAuthResult();
|
||||
EXPECT_TRUE(authResult != nullptr);
|
||||
if (authResult == nullptr) {
|
||||
return;
|
||||
}
|
||||
EXPECT_TRUE((authResult->ticket != nullptr) && (authResult->tokenValue != nullptr) &&
|
||||
(authResult->authStatus != nullptr));
|
||||
if (authResult->ticket != nullptr) {
|
||||
EXPECT_TRUE(strcmp(authResult->ticket, ATTEST_MOCK_HAL_TICKET) == 0);
|
||||
}
|
||||
DestroyAuthResult(&authResult);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestGenActiveMsg001
|
||||
* @tc.desc: Test gen active msg.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestGenActiveMsg001, TestSize.Level1)
|
||||
{
|
||||
AttestSetMockReadTokenRet(ATTEST_OK);
|
||||
// 初始化参数
|
||||
int32_t ret = InitSysData();
|
||||
EXPECT_TRUE(ret == DEVATTEST_SUCCESS);
|
||||
|
||||
DevicePacket* reqMsg = TddGenMsg(ATTEST_CASE_ACTIVE);
|
||||
EXPECT_TRUE((reqMsg != nullptr));
|
||||
if (reqMsg == NULL) {
|
||||
return;
|
||||
}
|
||||
char *outToken = reqMsg->tokenInfo.token;
|
||||
EXPECT_TRUE(outToken != nullptr);
|
||||
if (outToken == NULL) {
|
||||
FREE_DEVICE_PACKET(reqMsg);
|
||||
return;
|
||||
}
|
||||
EXPECT_TRUE(strcmp(outToken, ATTEST_ACTIVE_GEN_TOKEN) == 0);
|
||||
FREE_DEVICE_PACKET(reqMsg);
|
||||
// 恢复环境
|
||||
DestroySysData();
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestGenActiveMsg002
|
||||
* @tc.desc: Test gen auth msg without token.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestGenActiveMsg002, TestSize.Level1)
|
||||
{
|
||||
AttestSetMockReadTokenRet(TOKEN_UNPRESET);
|
||||
// 初始化参数
|
||||
int32_t ret = InitSysData();
|
||||
EXPECT_TRUE(ret == DEVATTEST_SUCCESS);
|
||||
|
||||
DevicePacket* reqMsg = TddGenMsg(ATTEST_CASE_ACTIVE);
|
||||
EXPECT_TRUE((reqMsg != nullptr));
|
||||
if (reqMsg == nullptr) {
|
||||
return;
|
||||
}
|
||||
char *outToken = reqMsg->tokenInfo.token;
|
||||
EXPECT_TRUE(outToken != nullptr);
|
||||
if (outToken == NULL) {
|
||||
FREE_DEVICE_PACKET(reqMsg);
|
||||
return;
|
||||
}
|
||||
#if defined(__ATTEST_ENABLE_PRESET_TOKEN__)
|
||||
EXPECT_TRUE(strcmp(ATTEST_ACTIVE_GEN_ONLINE_TOKEN, outToken) == 0);
|
||||
#else
|
||||
EXPECT_TRUE(strcmp(ATTEST_ACTIVE_GEN_PRODUCT_TOKEN, outToken) == 0);
|
||||
#endif
|
||||
FREE_DEVICE_PACKET(reqMsg);
|
||||
// 恢复环境
|
||||
DestroySysData();
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestParseActiveResult001
|
||||
* @tc.desc: Test parse active result,result is ok.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestParseActiveResult001, TestSize.Level1)
|
||||
{
|
||||
string input = "{\"errcode\":0}";
|
||||
int32_t ret = ParseActiveResult(input.c_str());
|
||||
EXPECT_TRUE(ret == DEVATTEST_SUCCESS);
|
||||
input = "{\"errcode\":\"-32s\"}";
|
||||
ret = ParseActiveResult(input.c_str());
|
||||
EXPECT_TRUE((ret != DEVATTEST_SUCCESS));
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestGetChallenge001
|
||||
* @tc.desc: Test get reset challenge.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestGetChallenge001, TestSize.Level1)
|
||||
{
|
||||
// 初始化环境
|
||||
int32_t ret = InitSysData();
|
||||
EXPECT_TRUE(ret == DEVATTEST_SUCCESS);
|
||||
(void)InitNetworkServerInfo();
|
||||
(void)D2CConnect();
|
||||
|
||||
g_netType = ATTEST_GET_CHANLLEGE;
|
||||
ChallengeResult* challenge = NULL;
|
||||
ret = GetChallenge(&challenge, ATTEST_ACTION_RESET);
|
||||
EXPECT_TRUE(ret == ATTEST_OK);
|
||||
EXPECT_TRUE(challenge != NULL);
|
||||
if (ret == ATTEST_OK && challenge != NULL) {
|
||||
EXPECT_TRUE(strcmp(ATTEST_RESET_EXPECT_CHAP, challenge->challenge) == 0);
|
||||
FREE_CHALLENGE_RESULT(challenge);
|
||||
}
|
||||
// 恢复环境
|
||||
DestroySysData();
|
||||
EXPECT_TRUE(StrdupDevInfo(VERSION_ID) == NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestSendResetMsg001
|
||||
* @tc.desc: Test send reset msg.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestSendResetMsg001, TestSize.Level1)
|
||||
{
|
||||
// 初始化环境
|
||||
int32_t ret = InitSysData();
|
||||
EXPECT_TRUE(ret == DEVATTEST_SUCCESS);
|
||||
(void)InitNetworkServerInfo();
|
||||
(void)D2CConnect();
|
||||
|
||||
g_netType = ATTEST_RESET;
|
||||
DevicePacket* reqMsg = TddGenMsg(ATTEST_CASE_RESET);
|
||||
if (reqMsg == NULL) {
|
||||
return;
|
||||
}
|
||||
char* respMsg = NULL;
|
||||
ret = SendResetMsg(reqMsg, &respMsg);
|
||||
EXPECT_TRUE((ret == ATTEST_OK) && (respMsg != NULL));
|
||||
FREE_DEVICE_PACKET(reqMsg);
|
||||
if ((ret == ATTEST_OK) && (respMsg != NULL)) {
|
||||
EXPECT_TRUE(strstr(respMsg, ATTEST_REST_ERROR_EXPECT_RESULT) != nullptr);
|
||||
free(respMsg);
|
||||
}
|
||||
// 恢复环境
|
||||
DestroySysData();
|
||||
EXPECT_TRUE(StrdupDevInfo(VERSION_ID) == NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestSendActiveMsg001
|
||||
* @tc.desc: Test send active msg.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestSendActiveMsg001, TestSize.Level1)
|
||||
{
|
||||
// 初始化环境
|
||||
int32_t ret = InitSysData();
|
||||
EXPECT_TRUE(ret == DEVATTEST_SUCCESS);
|
||||
|
||||
(void)InitNetworkServerInfo();
|
||||
(void)D2CConnect();
|
||||
|
||||
g_netType = ATTEST_ACTIVE;
|
||||
DevicePacket* reqMsg = TddGenMsg(ATTEST_CASE_ACTIVE);
|
||||
ASSERT_TRUE(reqMsg != NULL);
|
||||
|
||||
char* respMsg = NULL;
|
||||
ret = SendActiveMsg(reqMsg, &respMsg);
|
||||
EXPECT_TRUE((ret == ATTEST_OK) && (respMsg != NULL));
|
||||
FREE_DEVICE_PACKET(reqMsg);
|
||||
if ((ret == ATTEST_OK) && (respMsg != NULL)) {
|
||||
const char* ATTEST_ACTIVE_EXPECT_RESULT = "{\"errcode\":0}";
|
||||
EXPECT_TRUE(strcmp(ATTEST_ACTIVE_EXPECT_RESULT, respMsg) == 0);
|
||||
free(respMsg);
|
||||
}
|
||||
// 恢复环境
|
||||
DestroySysData();
|
||||
EXPECT_TRUE(StrdupDevInfo(VERSION_ID) == NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TestQueryAttestStatus001
|
||||
* @tc.desc: Test query attest status.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AttestTddTest, TestQueryAttestStatus001, TestSize.Level1)
|
||||
{
|
||||
AuthResult *authResult = GetAuthResult();
|
||||
if (authResult == nullptr) {
|
||||
return;
|
||||
}
|
||||
int32_t ret = FlushToken(authResult);
|
||||
EXPECT_TRUE((ret == DEVATTEST_SUCCESS));
|
||||
uint8_t authResultCode = ATTEST_RESULT_CODE;
|
||||
AttestWriteAuthResultCode((char*)&authResultCode, 1);
|
||||
AttestResultInfo attestResultInfo = { .softwareResultDetail = {-2, -2, -2, -2, -2} };
|
||||
attestResultInfo.ticket = NULL;
|
||||
ret = EntryGetAttestStatus(&attestResultInfo);
|
||||
EXPECT_TRUE((ret == ATTEST_OK) && (attestResultInfo.authResult == ATTEST_OK));
|
||||
EXPECT_TRUE((attestResultInfo.ticket != nullptr));
|
||||
if (attestResultInfo.ticket == nullptr) {
|
||||
return;
|
||||
}
|
||||
EXPECT_TRUE(strcmp(attestResultInfo.ticket, ATTEST_MOCK_HAL_TICKET) == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,5 @@
|
||||
import("//test/xts/device_attest_lite/build/devattestconfig.gni")
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
deps = [ "${devattest_path}/test/tdd/gtest:device_attest_tdd" ]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user