1 /* 2 * Copyright (C) 2022 Huawei Technologies Co., Ltd. 3 * Licensed under the Mulan PSL v2. 4 * You can use this software according to the terms and conditions of the Mulan PSL v2. 5 * You may obtain a copy of Mulan PSL v2 at: 6 * http://license.coscl.org.cn/MulanPSL2 7 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR 8 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR 9 * PURPOSE. 10 * See the Mulan PSL v2 for more details. 11 */ 12 13 #include <common_test.h> 14 #include <gtest/gtest.h> 15 #include <securec.h> 16 #include <tee_client_api.h> 17 #include <tee_client_type.h> 18 #include <test_defines.h> 19 #include <test_log.h> 20 #include <test_tcf_cmdid.h> 21 22 using namespace testing::ext; 23 /** 24 * @testcase.name : TEE_GetPropertyAsIdentity_WithoutEnum_SMC_TA_TESTIDENTITY 25 * @testcase.desc : test TA call TEE_GetPropertyAsIdentity to get value of SMC_TA_TESTIDENTITY 26 * @testcase.expect : return TEEC_SUCCESS 27 */ 28 TEE_TEST(TeeTCF2Test, TEE_GetPropertyAsIdentity_WithoutEnum_SMC_TA_TESTIDENTITY, Function | MediumTest | Level0) 29 { 30 TEEC_Result ret; 31 int rc; 32 TestData value = { 0 }; 33 value.cmd = CMD_TEE_GetPropertyAsIdentity; 34 value.propSet = TEE_PROPSET_CURRENT_TA; 35 rc = memcpy_s(value.inBuffer, BIG_SIZE, SMC_TA_TESTIDENTITY, sizeof(SMC_TA_TESTIDENTITY)); 36 ASSERT_EQ(rc, 0); 37 value.inBufferLen = sizeof(SMC_TA_TESTIDENTITY); 38 39 ret = Invoke_GetPropertyAsX(GetContext(), GetSession(), &value); 40 ASSERT_EQ(ret, TEEC_SUCCESS); 41 ASSERT_EQ(value.origin, TEEC_ORIGIN_TRUSTED_APP); 42 } 43 44 /** 45 * @testcase.name : TEE_GetPropertyAsIdentity_WithoutEnum_NameIsNull 46 * @testcase.desc : test TA call TEE_GetPropertyAsIdentity for name is null 47 * @testcase.expect : return TEEC_ERROR_ITEM_NOT_FOUND 48 */ 49 TEE_TEST(TeeTCF2Test, TEE_GetPropertyAsIdentity_WithoutEnum_NameIsNull, Function | MediumTest | Level0) 50 { 51 TEEC_Result ret; 52 53 TestData value = { 0 }; 54 value.cmd = CMD_TEE_GetPropertyAsIdentity; 55 value.caseId = INPUT_ISNULL; 56 value.propSet = TEE_PROPSET_CURRENT_TA; 57 58 ret = Invoke_GetPropertyAsX(GetContext(), GetSession(), &value); 59 ASSERT_EQ(ret, TEEC_ERROR_ITEM_NOT_FOUND); 60 ASSERT_EQ(value.origin, TEEC_ORIGIN_TRUSTED_APP); 61 } 62 63 /** 64 * @testcase.name : TEE_GetPropertyAsIdentity_WithoutEnum_NameIsZero 65 * @testcase.desc : test TA call TEE_GetPropertyAsIdentity for name value is zero 66 * @testcase.expect : return TEEC_ERROR_ITEM_NOT_FOUND 67 */ 68 TEE_TEST(TeeTCF2Test, TEE_GetPropertyAsIdentity_WithoutEnum_NameIsZero, Function | MediumTest | Level0) 69 { 70 TEEC_Result ret; 71 72 TestData value = { 0 }; 73 value.cmd = CMD_TEE_GetPropertyAsIdentity; 74 value.propSet = TEE_PROPSET_CURRENT_TA; 75 76 ret = Invoke_GetPropertyAsX(GetContext(), GetSession(), &value); 77 ASSERT_EQ(ret, TEEC_ERROR_ITEM_NOT_FOUND); 78 ASSERT_EQ(value.origin, TEEC_ORIGIN_TRUSTED_APP); 79 } 80 81 /** 82 * @testcase.name : TEE_GetPropertyAsIdentity_WithoutEnum_ValueBufferIsNULL 83 * @testcase.desc : test TA call TEE_GetPropertyAsIdentity for value buffer is null 84 * @testcase.expect : return TEEC_ERROR_BAD_PARAMETERS 85 */ 86 TEE_TEST(TeeTCF2Test, TEE_GetPropertyAsIdentity_WithoutEnum_ValueBufferIsNULL, Function | MediumTest | Level0) 87 { 88 TEEC_Result ret; 89 90 int rc; 91 TestData value = { 0 }; 92 value.cmd = CMD_TEE_GetPropertyAsIdentity; 93 value.caseId = OUTPUT_ISNULL; 94 value.propSet = TEE_PROPSET_CURRENT_TA; 95 rc = memcpy_s(value.inBuffer, BIG_SIZE, SMC_TA_TESTIDENTITY, sizeof(SMC_TA_TESTIDENTITY)); 96 ASSERT_EQ(rc, 0); 97 value.inBufferLen = sizeof(SMC_TA_TESTIDENTITY); 98 99 ret = Invoke_GetPropertyAsX(GetContext(), GetSession(), &value); 100 ASSERT_EQ(ret, TEEC_ERROR_BAD_PARAMETERS); 101 ASSERT_EQ(value.origin, TEEC_ORIGIN_TRUSTED_APP); 102 } 103 104 /** 105 * @testcase.name : TEE_GetPropertyAsIdentity_WithoutEnum_NameNotFound 106 * @testcase.desc : test TA call TEE_GetPropertyAsIdentity while Name Not Found 107 * @testcase.expect : return TEEC_ERROR_ITEM_NOT_FOUND 108 */ 109 TEE_TEST(TeeTCF2Test, TEE_GetPropertyAsIdentity_WithoutEnum_NameNotFound, Function | MediumTest | Level0) 110 { 111 TEEC_Result ret; 112 113 int rc; 114 TestData value = { 0 }; 115 value.cmd = CMD_TEE_GetPropertyAsIdentity; 116 value.propSet = TEE_PROPSET_CURRENT_TA; 117 rc = memcpy_s(value.inBuffer, BIG_SIZE, PROPERTY_NAME_UNKNOWN, sizeof(PROPERTY_NAME_UNKNOWN)); 118 ASSERT_EQ(rc, 0); 119 value.inBufferLen = sizeof(PROPERTY_NAME_UNKNOWN); 120 121 ret = Invoke_GetPropertyAsX(GetContext(), GetSession(), &value); 122 ASSERT_EQ(ret, TEEC_ERROR_ITEM_NOT_FOUND); 123 ASSERT_EQ(value.origin, TEEC_ORIGIN_TRUSTED_APP); 124 } 125 126 /** 127 * @testcase.name : TEE_GetPropertyAsIdentity_WithoutEnum_NameNotIdentity 128 * @testcase.desc : test TA call TEE_GetPropertyAsIdentity while Name type is not Identity 129 * @testcase.expect : return TEEC_ERROR_BAD_FORMAT 130 */ 131 TEE_TEST(TeeTCF2Test, TEE_GetPropertyAsIdentity_WithoutEnum_NameNotIdentity, Function | MediumTest | Level0) 132 { 133 TEEC_Result ret; 134 135 int rc; 136 TestData value = { 0 }; 137 value.cmd = CMD_TEE_GetPropertyAsIdentity; 138 value.propSet = TEE_PROPSET_CURRENT_TA; 139 rc = memcpy_s(value.inBuffer, BIG_SIZE, GPD_TA_SINGLEINSTANCE, sizeof(GPD_TA_SINGLEINSTANCE)); 140 ASSERT_EQ(rc, 0); 141 value.inBufferLen = sizeof(GPD_TA_SINGLEINSTANCE); 142 143 ret = Invoke_GetPropertyAsX(GetContext(), GetSession(), &value); 144 ASSERT_EQ(ret, TEEC_ERROR_BAD_FORMAT); 145 ASSERT_EQ(value.origin, TEEC_ORIGIN_TRUSTED_APP); 146 } 147 148 /** 149 * @testcase.name : TEE_GetPropertyAsIdentity_WithoutEnum_NameNotUUID2 150 * @testcase.desc : test TA call TEE_GetPropertyAsIdentity while Name type is not UUID, is string 151 * @testcase.expect : return TEEC_ERROR_BAD_FORMAT 152 */ 153 TEE_TEST(TeeTCF2Test, TEE_GetPropertyAsIdentity_WithoutEnum_NameNotUUID2, Function | MediumTest | Level0) 154 { 155 TEEC_Result ret; 156 157 int rc; 158 TestData value = { 0 }; 159 value.cmd = CMD_TEE_GetPropertyAsIdentity; 160 value.propSet = TEE_PROPSET_IMPLEMENTATION; 161 rc = memcpy_s(value.inBuffer, BIG_SIZE, GPD_TEE_DESCRIPTION, sizeof(GPD_TEE_DESCRIPTION)); 162 ASSERT_EQ(rc, 0); 163 value.inBufferLen = sizeof(GPD_TEE_DESCRIPTION); 164 165 ret = Invoke_GetPropertyAsX(GetContext(), GetSession(), &value); 166 ASSERT_EQ(ret, TEEC_ERROR_BAD_FORMAT); 167 ASSERT_EQ(value.origin, TEEC_ORIGIN_TRUSTED_APP); 168 } 169