mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
add total use count to statistics stored on auth keys
This commit is contained in:
parent
5877509a28
commit
b0c7895e81
2 changed files with 22 additions and 1 deletions
|
|
@ -65,6 +65,12 @@
|
||||||
"zh": "没用过",
|
"zh": "没用过",
|
||||||
"en-tts": "never"
|
"en-tts": "never"
|
||||||
},
|
},
|
||||||
|
"vault.u2f.appinfo.authcount": {
|
||||||
|
"en": "Usage count: ",
|
||||||
|
"ja": "使用回数: ",
|
||||||
|
"zh": "使用次数: ",
|
||||||
|
"en-tts": "Usage count: "
|
||||||
|
},
|
||||||
"vault.u2f.register": {
|
"vault.u2f.register": {
|
||||||
"en": "U2F Registration Request",
|
"en": "U2F Registration Request",
|
||||||
"ja": "U2F登録リクエスト",
|
"ja": "U2F登録リクエスト",
|
||||||
|
|
|
||||||
|
|
@ -299,6 +299,10 @@ pub(crate) fn start_ux_thread() {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
request_str.push_str(&format!("\n{}{}",
|
||||||
|
t!("vault.u2f.appinfo.authcount", xous::LANG),
|
||||||
|
info.count,
|
||||||
|
));
|
||||||
} else {
|
} else {
|
||||||
// no record of the app. Just give the hash.
|
// no record of the app. Just give the hash.
|
||||||
request_str.push_str(&format!("\n{}{}",
|
request_str.push_str(&format!("\n{}{}",
|
||||||
|
|
@ -431,6 +435,7 @@ pub(crate) fn start_ux_thread() {
|
||||||
let ser = if let Some(info) = &mut app_info {
|
let ser = if let Some(info) = &mut app_info {
|
||||||
// if an appinfo was found, just update it
|
// if an appinfo was found, just update it
|
||||||
info.atime = utc_now().timestamp() as u64;
|
info.atime = utc_now().timestamp() as u64;
|
||||||
|
info.count = info.count.saturating_add(1);
|
||||||
serialize_app_info(info)
|
serialize_app_info(info)
|
||||||
} else {
|
} else {
|
||||||
// otherwise, create it
|
// otherwise, create it
|
||||||
|
|
@ -445,6 +450,7 @@ pub(crate) fn start_ux_thread() {
|
||||||
id,
|
id,
|
||||||
ctime: utc_now().timestamp() as u64,
|
ctime: utc_now().timestamp() as u64,
|
||||||
atime: 0,
|
atime: 0,
|
||||||
|
count: 0,
|
||||||
};
|
};
|
||||||
serialize_app_info(&info)
|
serialize_app_info(&info)
|
||||||
}
|
}
|
||||||
|
|
@ -496,6 +502,7 @@ struct AppInfo {
|
||||||
id: [u8; 32],
|
id: [u8; 32],
|
||||||
ctime: u64,
|
ctime: u64,
|
||||||
atime: u64,
|
atime: u64,
|
||||||
|
count: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_app_info(descriptor: Vec::<u8>) -> Option::<AppInfo> {
|
fn deserialize_app_info(descriptor: Vec::<u8>) -> Option::<AppInfo> {
|
||||||
|
|
@ -505,6 +512,7 @@ fn deserialize_app_info(descriptor: Vec::<u8>) -> Option::<AppInfo> {
|
||||||
id: [0u8; 32],
|
id: [0u8; 32],
|
||||||
ctime: 0,
|
ctime: 0,
|
||||||
atime: 0,
|
atime: 0,
|
||||||
|
count: 0,
|
||||||
};
|
};
|
||||||
let lines = desc_str.split('\n');
|
let lines = desc_str.split('\n');
|
||||||
for line in lines {
|
for line in lines {
|
||||||
|
|
@ -534,6 +542,12 @@ fn deserialize_app_info(descriptor: Vec::<u8>) -> Option::<AppInfo> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"count" => {
|
||||||
|
if let Ok(count) = u64::from_str_radix(data, 10) {
|
||||||
|
appinfo.count = count;
|
||||||
|
}
|
||||||
|
// count was added later, so, we don't fail if we don't see the record.
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
log::warn!("unexpected tag {} encountered parsing app info, aborting", tag);
|
log::warn!("unexpected tag {} encountered parsing app info, aborting", tag);
|
||||||
return None;
|
return None;
|
||||||
|
|
@ -554,11 +568,12 @@ fn deserialize_app_info(descriptor: Vec::<u8>) -> Option::<AppInfo> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_app_info<'a>(appinfo: &AppInfo) -> Vec::<u8> {
|
fn serialize_app_info<'a>(appinfo: &AppInfo) -> Vec::<u8> {
|
||||||
format!("{}:{}\n{}:{}\n{}:{}\n{}:{}",
|
format!("{}:{}\n{}:{}\n{}:{}\n{}:{}\n{}:{}",
|
||||||
"name", appinfo.name,
|
"name", appinfo.name,
|
||||||
"id", hex::encode(appinfo.id),
|
"id", hex::encode(appinfo.id),
|
||||||
"ctime", appinfo.ctime,
|
"ctime", appinfo.ctime,
|
||||||
"atime", appinfo.atime,
|
"atime", appinfo.atime,
|
||||||
|
"count", appinfo.count,
|
||||||
).into_bytes()
|
).into_bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue