modify delete_on_package_removed

Change-Id: I8c7559c9de836a5e8010cec0072a2689c516aa25

Match-id-08fa19408e32231386bba1b0d56a699ff41ca0eb
This commit is contained in:
authName 2023-11-28 10:33:59 +08:00 committed by userName
parent 22fcb3e8de
commit f4d545cafa
2 changed files with 19 additions and 16 deletions

View File

@ -61,4 +61,3 @@
**[通用密钥库系统HUKS](https://gitee.com/openharmony/security_huks)**
**[统一用户认证UserIAM](https://gitee.com/openharmony/useriam_user_auth_framework)**

View File

@ -23,38 +23,42 @@ use asset_db_operator::{
database::Database,
types::{column, DbMap},
};
use asset_definition::{log_throw_error, ErrCode, Result, Value};
use asset_definition::{Result, Value};
use asset_file_operator::delete_user_db_dir;
use asset_log::{loge, logi};
use crate::sys_event::upload_fault_system_event;
fn delete_on_package_removed(user_id: i32, owner: Vec<u8>) -> Result<()> {
fn delete_on_package_removed(user_id: i32, owner: Vec<u8>) -> Result<bool> {
let mut cond = DbMap::new();
cond.insert(column::OWNER_TYPE, Value::Number(OwnerType::Hap as u32));
cond.insert(column::OWNER, Value::Bytes(owner.clone()));
cond.insert(column::OWNER, Value::Bytes(owner));
cond.insert(column::IS_PERSISTENT, Value::Bool(false));
let mut db = Database::build(user_id)?;
let _ = db.delete_datas(&cond)?;
let calling_info = CallingInfo::new(user_id, OwnerType::Hap, owner);
cond.insert(column::IS_PERSISTENT, Value::Bool(true));
match db.query_datas(&vec![], &cond, None) {
Ok(data) if !data.is_empty() => SecretKey::delete_by_owner(&calling_info),
Ok(_) => {
logi!("The owner wants to retain data after uninstallation. Do not delete key in HUKS!");
Ok(())
},
Err(e) => {
log_throw_error!(ErrCode::DatabaseError, "Querying the owner's remain data failed, ErrorCode:[{}]", e.code)
},
}
db.is_data_exists(&cond)
}
extern "C" fn delete_data_by_owner(user_id: i32, owner: *const u8, owner_size: u32) {
let owner: Vec<u8> = unsafe { slice::from_raw_parts(owner, owner_size as usize).to_vec() };
let res = delete_on_package_removed(user_id, owner);
let calling_info = CallingInfo::new(user_id, OwnerType::Hap, owner.clone());
let res = match delete_on_package_removed(user_id, owner) {
Ok(true) => {
logi!("The owner wants to retain data after uninstallation. Do not delete key in HUKS!");
Ok(())
},
Ok(false) => SecretKey::delete_by_owner(&calling_info),
Err(e) => {
// Report the database operation fault event.
upload_fault_system_event(&calling_info, "on_package_removed", &e);
SecretKey::delete_by_owner(&calling_info)
},
};
if let Err(e) = res {
// Report the key operation fault event.
let calling_info = CallingInfo::new_self();
upload_fault_system_event(&calling_info, "on_package_removed", &e);
}