Skip to content

Commit

Permalink
fix: ding bot push msg timestamp error
Browse files Browse the repository at this point in the history
  • Loading branch information
fan-tastic-z committed Jun 3, 2024
1 parent f04412a commit 752aac0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "watchvuln-rs"
version = "0.1.1"
version = "0.1.4"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
12 changes: 8 additions & 4 deletions src/push/dingding.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::time::SystemTime;

use crate::{
error::{Error, Result},
utils::{calc_hmac_sha256, http_client::Help},
Expand Down Expand Up @@ -72,16 +74,18 @@ impl DingDing {
Help::new(headers)
}
pub fn generate_sign(&self) -> Result<Sign> {
let now = chrono::Local::now().timestamp();
let timestamp_and_secret = &format!("{}\n{}", now, self.secret_token);
let timestamp = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)?
.as_millis();
let timestamp_and_secret = &format!("{}\n{}", timestamp, self.secret_token);
let hmac_sha256 = calc_hmac_sha256(
self.secret_token.as_bytes(),
timestamp_and_secret.as_bytes(),
)?;
let sign = BASE64_STANDARD.encode(hmac_sha256);
Ok(Sign {
access_token: self.access_token.clone(),
timestamp: now,
timestamp,
sign,
})
}
Expand All @@ -96,6 +100,6 @@ pub struct DingResponse {
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Sign {
pub access_token: String,
pub timestamp: i64,
pub timestamp: u128,
pub sign: String,
}
7 changes: 4 additions & 3 deletions src/push/msg_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ const INIT_MSG_TEMPLATE: &str = r#"
当前版本: {{ version }}
本地漏洞数量: {{ vuln_count }}
检查周期配置: {{ cron_config }}
目前爬取的数据源:{% for v in grabs %}
{{ loop.index }}.{{ v }}{% endfor %}"#;
目前爬取的数据源:
{% for v in grabs %}
{{ loop.index }}.{{ v }}
{% endfor %}"#;

const MAX_REFERENCE_LENGTH: usize = 8;

Expand Down

0 comments on commit 752aac0

Please sign in to comment.