modify auth token length to 280

Signed-off-by: 尹耀德 <yinyaode1@huawei.com>
This commit is contained in:
尹耀德 2024-04-25 14:19:31 +08:00
parent a3b12e31a0
commit bc2943d7d1
12 changed files with 199 additions and 22 deletions

View File

@ -11,12 +11,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
import("//base/security/asset/asset.gni")
import("//build/ohos.gni")
group("asset_component") {
deps = [
"interfaces/inner_api/rs:asset_sdk",
"interfaces/inner_api/rs:asset_sdk_rust",
"interfaces/kits/c:asset_ndk",
"sa_profile:asset_sa_profiles",
"services/core_service:asset_service",
@ -35,8 +35,8 @@ group("asset_bin_test") {
"test/unittest/module_test:asset_dependency_test",
]
if (enable_local_test) {
deps += ["test/unittest/inner_api_rust:asset_rust_test"]
deps += ["test/unittest/module_test:asset_module_test"]
deps += ["services/db_operator:asset_db_operator_test"]
deps += [ "test/unittest/inner_api_rust:asset_rust_test" ]
deps += [ "test/unittest/module_test:asset_module_test" ]
deps += [ "services/db_operator:asset_db_operator_test" ]
}
}

View File

@ -57,7 +57,7 @@
},
"inner_api": [
{
"name": "//base/security/asset/interfaces/inner_api/rs:asset_sdk",
"name": "//base/security/asset/interfaces/inner_api/rs:asset_sdk_rust",
"header": {
"header_files": [],
"header_base": []

View File

@ -55,7 +55,7 @@ ohos_rust_shared_ffi("asset_sdk_ffi") {
deps = [
"../../../frameworks/os_dependency/log:asset_log",
"../../../frameworks/os_dependency/memory:asset_mem",
"../rs:asset_sdk",
"../rs:asset_sdk_rust",
]
crate_name = "asset_sdk_ffi"
subsystem_name = "security"

View File

@ -13,7 +13,7 @@
import("//build/ohos.gni")
ohos_rust_shared_library("asset_sdk") {
ohos_rust_shared_library("asset_sdk_rust") {
sources = [ "src/lib.rs" ]
deps = [
"../../../frameworks/definition:asset_definition",

View File

@ -72,7 +72,6 @@ pub fn get_user_id(uid: u64) -> Result<i32> {
}
/// Check user id exist.
#[allow(dead_code)]
pub fn is_user_id_exist(user_id: i32) -> Result<bool> {
unsafe {
let mut exist = false;

View File

@ -15,7 +15,7 @@
//! This module is used to verify the validity of asset attributes.
use asset_constants::ROOT_USER_UPPERBOUND;
use asset_constants::{is_user_id_exist, ROOT_USER_UPPERBOUND};
use asset_definition::{
log_throw_error, Accessibility, AssetMap, AuthType, ConflictResolution, Conversion, ErrCode, Result, ReturnType,
Tag, Value,
@ -157,7 +157,17 @@ fn check_data_value(tag: &Tag, value: &Value) -> Result<()> {
Tag::ReturnOrderedBy => {
check_tag_range(tag, value, &[CRITICAL_LABEL_ATTRS, NORMAL_LABEL_ATTRS, NORMAL_LOCAL_LABEL_ATTRS].concat())
},
Tag::UserId => check_number_range(tag, value, ROOT_USER_UPPERBOUND, i32::MAX as u32),
Tag::UserId => {
check_number_range(tag, value, ROOT_USER_UPPERBOUND, i32::MAX as u32)?;
let Value::Number(n) = value else {
return log_throw_error!(ErrCode::InvalidArgument, "[FATAL][{}] is not a number.", tag);
};
match is_user_id_exist(*n as i32) {
Ok(res) if res => Ok(()),
Ok(_) => log_throw_error!(ErrCode::InvalidArgument, "[FATAL]The user id [{}] is not exist.", *n),
Err(e) => Err(e),
}
},
Tag::UpdateTime => check_array_size(tag, value, MIN_ARRAY_SIZE, MAX_TIME_SIZE),
}
}

View File

@ -19,7 +19,7 @@ module_output_path = "asset/asset_UT_test"
ohos_rust_unittest("asset_rust_test") {
module_out_path = module_output_path
sources = [ "src/main.rs" ]
deps = [ "../../../interfaces/inner_api/rs:asset_sdk" ]
deps = [ "../../../interfaces/inner_api/rs:asset_sdk_rust" ]
subsystem_name = "security"
part_name = "asset"
}

View File

@ -46,16 +46,17 @@ ohos_unittest("asset_dependency_test") {
"../../../services/crypto_manager/src",
"../common/inc",
]
sources = [
sources = []
if (enable_local_test) {
sources += [ "src/asset_system_api_test.cpp" ]
sources += [ "src/huks_wrapper_test.cpp" ]
}
sources += [
"src/bms_wrapper_test.cpp",
"src/os_account_wrapper_test.cpp",
"src/system_ability_wrapper_test.cpp",
"src/system_event_wrapper_test.cpp",
]
if (enable_local_test) {
sources += [ "src/asset_system_api_test.cpp" ]
sources += [ "src/huks_wrapper_test.cpp" ]
}
deps = [
"../../../interfaces/inner_api/c:asset_sdk",
"../../../interfaces/kits/c:asset_ndk",

View File

@ -16,6 +16,8 @@
#ifndef ASSET_SYSTEM_API_TEST_H
#define ASSET_SYSTEM_API_TEST_H
#define NOT_FOUND_USER_ID 103
namespace UnitTest::AssetSystemApiTest {
int AssetSystemApiTest001(void);
int AssetSystemApiTest002(void);
@ -27,6 +29,14 @@ int AssetSystemApiTest007(void);
int AssetSystemApiTest008(void);
int AssetSystemApiTest009(void);
int AssetSystemApiTest010(void);
int AssetSystemApiTest011(void);
int AssetSystemApiTest012(void);
int AssetSystemApiTest013(void);
int AssetSystemApiTest014(void);
int AssetSystemApiTest015(void);
int AssetSystemApiTest016(void);
int AssetSystemApiTest017(void);
int AssetSystemApiTest018(void);
}
#endif // ASSET_SYSTEM_API_TEST_H

View File

@ -299,7 +299,7 @@ HWTEST_F(AssetSystemApiTest, AssetSystemApiTest006, TestSize.Level0)
/**
* @tc.name: AssetSystemApiTest.AssetSystemApiTest007
* @tc.desc: Test asset func AssetQuery expect SUCCESS
* @tc.desc: Test asset func AssetQuery expect FAIL
* @tc.type: FUNC
* @tc.result:0
*/
@ -394,4 +394,161 @@ HWTEST_F(AssetSystemApiTest, AssetSystemApiTest010, TestSize.Level0)
};
ASSERT_EQ(SEC_ASSET_INVALID_ARGUMENT, AssetPostQuery(attr2, ARRAY_SIZE(attr2)));
}
/**
* @tc.name: AssetSystemApiTest.AssetSystemApiTest011
* @tc.desc: Test asset func AssetAdd expect FAIL
* @tc.type: FUNC
* @tc.result:0
*/
HWTEST_F(AssetSystemApiTest, AssetSystemApiTest011, TestSize.Level0)
{
AssetBlob funcName = { .size = strlen(__func__), .data = reinterpret_cast<uint8_t*>(const_cast<char*>(__func__)) };
AssetAttr attr[] = {
{ .tag = SEC_ASSET_TAG_ALIAS, .value.blob = funcName },
{ .tag = SEC_ASSET_TAG_SECRET, .value.blob = funcName },
{ .tag = SEC_ASSET_TAG_USER_ID, .value.u32 = NOT_FOUND_USER_ID },
{ .tag = SEC_ASSET_TAG_ACCESSIBILITY, .value.u32 = SEC_ASSET_ACCESSIBILITY_DEVICE_UNLOCKED },
{ .tag = SEC_ASSET_TAG_AUTH_TYPE, .value.u32 = SEC_ASSET_AUTH_TYPE_ANY }
};
ASSERT_EQ(SEC_ASSET_INVALID_ARGUMENT, AssetAdd(attr, ARRAY_SIZE(attr)));
}
/**
* @tc.name: AssetSystemApiTest.AssetSystemApiTest012
* @tc.desc: Test asset func AssetQuery expect FAIL
* @tc.type: FUNC
* @tc.result:0
*/
HWTEST_F(AssetSystemApiTest, AssetSystemApiTest012, TestSize.Level0)
{
AssetBlob funcName = { .size = strlen(__func__), .data = reinterpret_cast<uint8_t*>(const_cast<char*>(__func__)) };
AssetResultSet resultSet = { 0 };
AssetAttr queryAttr[] = {
{ .tag = SEC_ASSET_TAG_ALIAS, .value.blob = funcName },
{ .tag = SEC_ASSET_TAG_USER_ID, .value.u32 = NOT_FOUND_USER_ID },
{ .tag = SEC_ASSET_TAG_RETURN_TYPE, .value.u32 = SEC_ASSET_RETURN_ALL }
};
ASSERT_EQ(SEC_ASSET_INVALID_ARGUMENT, AssetQuery(queryAttr, ARRAY_SIZE(queryAttr), &resultSet));
}
/**
* @tc.name: AssetSystemApiTest.AssetSystemApiTest013
* @tc.desc: Test asset func AssetRemove expect FAIL
* @tc.type: FUNC
* @tc.result:0
*/
HWTEST_F(AssetSystemApiTest, AssetSystemApiTest013, TestSize.Level0)
{
AssetBlob funcName = { .size = strlen(__func__), .data = reinterpret_cast<uint8_t*>(const_cast<char*>(__func__)) };
AssetAttr attr[] = {
{ .tag = SEC_ASSET_TAG_ALIAS, .value.blob = funcName },
{ .tag = SEC_ASSET_TAG_ACCESSIBILITY, .value.u32 = SEC_ASSET_ACCESSIBILITY_DEVICE_UNLOCKED },
{ .tag = SEC_ASSET_TAG_REQUIRE_PASSWORD_SET, .value.boolean = false },
{ .tag = SEC_ASSET_TAG_USER_ID, .value.u32 = NOT_FOUND_USER_ID },
{ .tag = SEC_ASSET_TAG_AUTH_TYPE, .value.u32 = SEC_ASSET_AUTH_TYPE_NONE },
{ .tag = SEC_ASSET_TAG_SYNC_TYPE, .value.u32 = SEC_ASSET_SYNC_TYPE_NEVER },
{ .tag = SEC_ASSET_TAG_IS_PERSISTENT, .value.boolean = false }
};
ASSERT_EQ(SEC_ASSET_INVALID_ARGUMENT, AssetRemove(attr, ARRAY_SIZE(attr)));
}
/**
* @tc.name: AssetSystemApiTest.AssetSystemApiTest014
* @tc.desc: Test asset func AssetPreQuery expect FAIL
* @tc.type: FUNC
* @tc.result:0
*/
HWTEST_F(AssetSystemApiTest, AssetSystemApiTest014, TestSize.Level0)
{
AssetBlob funcName = { .size = strlen(__func__), .data = reinterpret_cast<uint8_t*>(const_cast<char*>(__func__)) };
AssetBlob challenge = { 0 };
AssetAttr attr[] = {
{ .tag = SEC_ASSET_TAG_ALIAS, .value.blob = funcName },
{ .tag = SEC_ASSET_TAG_USER_ID, .value.u32 = NOT_FOUND_USER_ID }
};
ASSERT_EQ(SEC_ASSET_INVALID_ARGUMENT, AssetPreQuery(attr, ARRAY_SIZE(attr), &challenge));
}
/**
* @tc.name: AssetSystemApiTest.AssetSystemApiTest015
* @tc.desc: Test asset func AssetPostQuery expect FAIL
* @tc.type: FUNC
* @tc.result:0
*/
HWTEST_F(AssetSystemApiTest, AssetSystemApiTest015, TestSize.Level0)
{
AssetBlob challenge = { 0 };
AssetAttr attr[] = {
{ .tag = SEC_ASSET_TAG_AUTH_CHALLENGE, .value.blob = challenge },
{ .tag = SEC_ASSET_TAG_USER_ID, .value.u32 = NOT_FOUND_USER_ID }
};
ASSERT_EQ(SEC_ASSET_INVALID_ARGUMENT, AssetPostQuery(attr, ARRAY_SIZE(attr)));
}
/**
* @tc.name: AssetSystemApiTest.AssetSystemApiTest016
* @tc.desc: Test asset func AssetUpdate expect FAIL
* @tc.type: FUNC
* @tc.result:0
*/
HWTEST_F(AssetSystemApiTest, AssetSystemApiTest016, TestSize.Level0)
{
AssetBlob funcName = { .size = strlen(__func__), .data = reinterpret_cast<uint8_t*>(const_cast<char*>(__func__)) };
AssetAttr queryAttr[] = {
{ .tag = SEC_ASSET_TAG_ALIAS, .value.blob = funcName },
{ .tag = SEC_ASSET_TAG_USER_ID, .value.u32 = NOT_FOUND_USER_ID },
};
const char *secretNew = "secret_new";
AssetAttr updateAttr[] = {
{ .tag = SEC_ASSET_TAG_SECRET, .value.blob =
{ .size = strlen(secretNew), .data = reinterpret_cast<uint8_t*>(const_cast<char*>(secretNew)) } }
};
ASSERT_EQ(SEC_ASSET_INVALID_ARGUMENT,
AssetUpdate(queryAttr, ARRAY_SIZE(queryAttr), updateAttr, ARRAY_SIZE(updateAttr)));
}
/**
* @tc.name: AssetSystemApiTest.AssetSystemApiTest017
* @tc.desc: Test asset func AssetUpdate expect FAIL
* @tc.type: FUNC
* @tc.result:0
*/
HWTEST_F(AssetSystemApiTest, AssetSystemApiTest017, TestSize.Level0)
{
AssetBlob funcName = { .size = strlen(__func__), .data = reinterpret_cast<uint8_t*>(const_cast<char*>(__func__)) };
AssetAttr queryAttr[] = {
{ .tag = SEC_ASSET_TAG_ALIAS, .value.blob = funcName },
{ .tag = SEC_ASSET_TAG_USER_ID, .value.u32 = 0 },
};
const char *secretNew = "secret_new";
AssetAttr updateAttr[] = {
{ .tag = SEC_ASSET_TAG_SECRET, .value.blob =
{ .size = strlen(secretNew), .data = reinterpret_cast<uint8_t*>(const_cast<char*>(secretNew)) } }
};
ASSERT_EQ(SEC_ASSET_INVALID_ARGUMENT,
AssetUpdate(queryAttr, ARRAY_SIZE(queryAttr), updateAttr, ARRAY_SIZE(updateAttr)));
}
/**
* @tc.name: AssetSystemApiTest.AssetSystemApiTest018
* @tc.desc: Test asset func AssetUpdate expect FAIL
* @tc.type: FUNC
* @tc.result:0
*/
HWTEST_F(AssetSystemApiTest, AssetSystemApiTest018, TestSize.Level0)
{
AssetBlob funcName = { .size = strlen(__func__), .data = reinterpret_cast<uint8_t*>(const_cast<char*>(__func__)) };
AssetAttr queryAttr[] = {
{ .tag = SEC_ASSET_TAG_ALIAS, .value.blob = funcName },
{ .tag = SEC_ASSET_TAG_USER_ID, .value.u32 = -1 },
};
const char *secretNew = "secret_new";
AssetAttr updateAttr[] = {
{ .tag = SEC_ASSET_TAG_SECRET, .value.blob =
{ .size = strlen(secretNew), .data = reinterpret_cast<uint8_t*>(const_cast<char*>(secretNew)) } }
};
ASSERT_EQ(SEC_ASSET_INVALID_ARGUMENT,
AssetUpdate(queryAttr, ARRAY_SIZE(queryAttr), updateAttr, ARRAY_SIZE(updateAttr)));
}
}

View File

@ -78,7 +78,7 @@ HWTEST_F(AssetBmsWrapperTest, AssetBmsWrapperTest002, TestSize.Level0)
uint8_t ownerInfo[256] = { 0 };
uint32_t infoLen = 256;
int32_t userId = 0;
uint64_t uid = 0;
uint64_t uid = 6226;
ASSERT_EQ(SEC_ASSET_INVALID_ARGUMENT, GetOwnerInfo(userId, uid, ownerType, ownerInfo, &infoLen));
}
@ -94,7 +94,7 @@ HWTEST_F(AssetBmsWrapperTest, AssetBmsWrapperTest003, TestSize.Level0)
uint8_t* ownerInfo = nullptr;
uint32_t infoLen = 256;
int32_t userId = 0;
uint64_t uid = 0;
uint64_t uid = 6226;
ASSERT_EQ(SEC_ASSET_INVALID_ARGUMENT, GetOwnerInfo(userId, uid, &ownerType, ownerInfo, &infoLen));
}
@ -110,7 +110,7 @@ HWTEST_F(AssetBmsWrapperTest, AssetBmsWrapperTest004, TestSize.Level0)
uint8_t ownerInfo[256] = { 0 };
uint32_t* infoLen = nullptr;
int32_t userId = 0;
uint64_t uid = 0;
uint64_t uid = 6226;
ASSERT_EQ(SEC_ASSET_INVALID_ARGUMENT, GetOwnerInfo(userId, uid, &ownerType, ownerInfo, infoLen));
}
}

View File

@ -58,7 +58,7 @@ void AssetOsAccountWrapperTest::TearDown(void)
HWTEST_F(AssetOsAccountWrapperTest, AssetOsAccountWrapperTest001, TestSize.Level0)
{
int32_t userId = 1000;
uint32_t uid = 0;
uint32_t uid = 6226;
ASSERT_EQ(true, GetUserIdByUid(uid, &userId));
}