From ce163195d55875589eff689276e0eaf921c4f3e3 Mon Sep 17 00:00:00 2001 From: sunmingze Date: Tue, 18 Apr 2023 17:41:33 +0800 Subject: [PATCH] modify xts_lite Signed-off-by: sunmingze --- .../src/device_attest_querry.cpp | 19 ++++- .../src/device_attest.c | 79 ++++++++++++++++++- 2 files changed, 95 insertions(+), 3 deletions(-) diff --git a/xts_lite/device_attest_lite/device_attestQuerry_posix/src/device_attest_querry.cpp b/xts_lite/device_attest_lite/device_attestQuerry_posix/src/device_attest_querry.cpp index ce0cb04a9..f2266af80 100644 --- a/xts_lite/device_attest_lite/device_attestQuerry_posix/src/device_attest_querry.cpp +++ b/xts_lite/device_attest_lite/device_attestQuerry_posix/src/device_attest_querry.cpp @@ -72,7 +72,7 @@ public: result = false; } if (!AttestStatusNumberValid(attestResultInfo.softwareResultDetail[SOFTWARE_RESULT_RESERVE])) { - failString += string(" reserveResult is ") + to_string(attestResultInfo.softwareResultDetail[SOFTWARE_RESULT_PCID]); + failString += string(" reserveResult is ") + to_string(attestResultInfo.softwareResultDetail[SOFTWARE_RESULT_RESERVE]); result = false; } if (attestResultInfo.authResult == DEVATTEST_SUCCESS) { @@ -119,6 +119,21 @@ HWTEST_F(DeviceAttestQuerryTest, subDeviceAttestTest0200, Function | MediumTest * @tc.name : HiLog::Warn parameter legal test (Cortex-A, C) * @tc.desc : [C- SOFTWARE -0200] */ +#ifdef __LINUX__ +HWTEST_F(DeviceAttestQuerryTest, subDeviceAttestTest0300, Function | MediumTest | Level1) +{ + int32_t ret = DEVATTEST_SUCCESS; + ret = StartDevAttestTask(); + printf("[CLIENT MAIN] StartDevAttestTask ret:%d.\n", ret); + EXPECT_EQ(ret, DEVATTEST_SUCCESS); + AttestResultInfo attestResultInfo = { 0 }; + attestResultInfo.ticket = NULL; + printf("[CLIENT MAIN] query.\n"); + ret = GetAttestStatus(&attestResultInfo); + printf("[CLIENT MAIN] wrong. ret:%d\n", ret); + EXPECT_EQ(ret, DEVATTEST_SUCCESS); +} +#else HWTEST_F(DeviceAttestQuerryTest, subDeviceAttestTest0300, Function | MediumTest | Level1) { int32_t ret = DEVATTEST_SUCCESS; @@ -132,3 +147,5 @@ HWTEST_F(DeviceAttestQuerryTest, subDeviceAttestTest0300, Function | MediumTest printf("[CLIENT MAIN] wrong. ret:%d\n", ret); EXPECT_FALSE(ret == DEVATTEST_SUCCESS); } +#endif + diff --git a/xts_lite/device_attest_lite/device_attestStart_hal/src/device_attest.c b/xts_lite/device_attest_lite/device_attestStart_hal/src/device_attest.c index f76688613..d2496ad8b 100644 --- a/xts_lite/device_attest_lite/device_attestStart_hal/src/device_attest.c +++ b/xts_lite/device_attest_lite/device_attestStart_hal/src/device_attest.c @@ -17,6 +17,17 @@ #include "hctest.h" #include "devattest_interface.h" +#define DEVATTEST_INIT -2 +#define DEVATTEST_SUCCESS 0 + +typedef enum { + SOFTWARE_RESULT_VERSIONID, + SOFTWARE_RESULT_PATCHLEVEL, + SOFTWARE_RESULT_ROOTHASH, + SOFTWARE_RESULT_PCID, + SOFTWARE_RESULT_RESERVE, +} SOFTWARE_RESULT_DETAIL_TYPE; + /** * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency * @param : subsystem name is dfx @@ -44,8 +55,55 @@ static BOOL DeviceAttestFuncTestSuiteTearDown(void) return TRUE; } +bool AttestStatusNumberValid(int32_t attestStatusNumber) +{ + if (attestStatusNumber < DEVATTEST_INIT || attestStatusNumber > DEVATTEST_SUCCESS) { + return false; + } + return true; +} + +bool AttestStatusValid(AttestResultInfo attestResultInfo) +{ + bool result = true; + if (!AttestStatusNumberValid(attestResultInfo.authResult)) { + result = false; + } + if (!AttestStatusNumberValid(attestResultInfo.softwareResult)) { + result = false; + } + if (!AttestStatusNumberValid(attestResultInfo.softwareResultDetail[SOFTWARE_RESULT_VERSIONID])) { + result = false; + } + if (!AttestStatusNumberValid(attestResultInfo.softwareResultDetail[SOFTWARE_RESULT_PATCHLEVEL])) { + result = false; + } + if (!AttestStatusNumberValid(attestResultInfo.softwareResultDetail[SOFTWARE_RESULT_ROOTHASH])) { + result = false; + } + if (!AttestStatusNumberValid(attestResultInfo.softwareResultDetail[SOFTWARE_RESULT_PCID])) { + result = false; + } + if (!AttestStatusNumberValid(attestResultInfo.softwareResultDetail[SOFTWARE_RESULT_RESERVE])) { + result = false; + } + if (attestResultInfo.authResult == DEVATTEST_SUCCESS) { + if (attestResultInfo.ticketLength <= 0) { + result = false; + } + if (attestResultInfo.ticket == "") { + result = false; + } + } + if (result) { + return true; + } else { + return false; + } +} + /** - * @tc.number : SUB_Device_Attest_0600 + * @tc.number : SUB_Device_Attest_0100 * @tc.name : StartDevAttestTask test * @tc.desc : [C- SOFTWARE -0200] * @tc.size : MEDIUM @@ -56,8 +114,25 @@ LITE_TEST_CASE(DeviceAttestFuncTestSuite, subDeviceAttest0100, LEVEL0) { int32_t ret = DEVATTEST_SUCCESS; ret = StartDevAttestTask(); - printf("[CLIENT MAIN] StartDevAttestTask ret:%d.\n", ret); TEST_ASSERT_EQUAL_INT(ret, DEVATTEST_SUCCESS); }; +/** + * @tc.number : SUB_Device_Attest_0200 + * @tc.name : GetAttestStatus test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 0 + */ +LITE_TEST_CASE(DeviceAttestFuncTestSuite, subDeviceAttest0200, LEVEL0) +{ + int32_t ret = DEVATTEST_SUCCESS; + AttestResultInfo attestResultInfo = { 0 }; + attestResultInfo.ticket = NULL; + ret = GetAttestStatus(&attestResultInfo); + TEST_ASSERT_EQUAL_INT(ret, DEVATTEST_SUCCESS); + TEST_ASSERT_EQUAL_INT(AttestStatusValid(attestResultInfo), true); +}; + RUN_TEST_SUITE(DeviceAttestFuncTestSuite); -- GitLab