增加密钥hash,方便客户端判断加密是否一致

This commit is contained in:
lbl8603
2024-04-20 21:27:35 +08:00
parent 0cbc3e0f63
commit 137efe20b8
9 changed files with 67 additions and 10 deletions
+2
View File
@@ -36,5 +36,7 @@ pub struct DeviceItem {
pub rt: String,
pub status: String,
pub client_secret: bool,
pub client_secret_hash: Vec<u8>,
pub current_client_secret: bool,
pub current_client_secret_hash: Vec<u8>,
}
+3
View File
@@ -85,6 +85,7 @@ pub fn command_list(vnt: &Vnt) -> Vec<DeviceItem> {
let device_list = vnt.device_list();
let mut list = Vec::new();
let current_client_secret = vnt.client_encrypt();
let client_encrypt_hash = vnt.client_encrypt_hash().unwrap_or(&[]);
for peer in device_list {
let name = peer.name;
let virtual_ip = peer.virtual_ip.to_string();
@@ -153,7 +154,9 @@ pub fn command_list(vnt: &Vnt) -> Vec<DeviceItem> {
rt,
status,
client_secret,
client_secret_hash: peer.client_secret_hash,
current_client_secret,
current_client_secret_hash: client_encrypt_hash.to_vec(),
};
list.push(item);
}
+7 -2
View File
@@ -21,6 +21,7 @@ pub fn console_info(status: Info) {
println!("Up: {}", style(convert(status.up)).green());
println!("Down: {}", style(convert(status.down)).green());
}
fn convert(num: u64) -> String {
let gigabytes = num / (1024 * 1024 * 1024);
let remaining_bytes = num % (1024 * 1024 * 1024);
@@ -90,13 +91,17 @@ pub fn console_device_list(mut list: Vec<DeviceItem>) {
]);
for item in list {
if &item.status == "Online" {
if item.client_secret != item.current_client_secret {
if item.client_secret != item.current_client_secret
|| (!item.current_client_secret_hash.is_empty()
&& !item.client_secret_hash.is_empty()
&& item.current_client_secret_hash != item.client_secret_hash)
{
//加密状态不一致,无法通信的
out_list.push(vec![
(item.name, Style::new().red()),
(item.virtual_ip, Style::new().red()),
(item.status, Style::new().red()),
("".to_string(), Style::new().red()),
("Mismatch".to_string(), Style::new().red()),
("".to_string(), Style::new().red()),
]);
} else {