Skip to content

Commit 9f6fbe7

Browse files
committed
switch sha1 signature check to sha256
1 parent ee0b821 commit 9f6fbe7

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ rmp-serde = "1.1"
2727
brotli = "3.3.3"
2828
semver = "1.0"
2929
hmac = "0.12"
30-
sha1 = "0.10"
30+
sha2 = "0.10"
3131
hex = "0.4.2"
3232
regex = "1"
3333
toml = "0.7"

site/src/server.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use brotli::enc::BrotliEncoderParams;
22
use brotli::BrotliCompress;
33
use hmac::{Hmac, Mac};
4+
use sha2::Sha256;
45
use std::collections::HashMap;
56
use std::net::SocketAddr;
67
use std::path::Path;
@@ -18,7 +19,6 @@ use log::{debug, error, info};
1819
use parking_lot::{Mutex, RwLock};
1920
use serde::de::DeserializeOwned;
2021
use serde::Serialize;
21-
use sha1::Sha1;
2222
use uuid::Uuid;
2323

2424
pub use crate::api::{
@@ -690,23 +690,25 @@ fn not_found() -> http::Response<hyper::Body> {
690690
}
691691

692692
fn verify_gh(config: &Config, req: &http::request::Parts, body: &[u8]) -> bool {
693-
let gh_header = req.headers.get("X-Hub-Signature").cloned();
694-
let gh_header = gh_header.and_then(|g| g.to_str().ok().map(|s| s.to_owned()));
693+
let gh_header = req
694+
.headers
695+
.get("X-Hub-Signature-256")
696+
.and_then(|g| g.to_str().ok());
695697
let gh_header = match gh_header {
696698
Some(v) => v,
697699
None => return false,
698700
};
699-
verify_gh_sig(config, &gh_header, body).unwrap_or(false)
701+
verify_gh_sig(config, gh_header, body).unwrap_or(false)
700702
}
701703

702704
fn verify_gh_sig(cfg: &Config, header: &str, body: &[u8]) -> Option<bool> {
703-
type HmacSha1 = Hmac<Sha1>;
705+
type HmacSha256 = Hmac<Sha256>;
704706

705707
let mut mac =
706-
HmacSha1::new_from_slice(cfg.keys.github_webhook_secret.as_ref().unwrap().as_bytes())
708+
HmacSha256::new_from_slice(cfg.keys.github_webhook_secret.as_ref().unwrap().as_bytes())
707709
.expect("HMAC can take key of any size");
708710
mac.update(body);
709-
let sha = header.get(5..)?; // strip sha1=
711+
let sha = header.strip_prefix("sha256=")?;
710712
let sha = hex::decode(sha).ok()?;
711713
if let Ok(()) = mac.verify_slice(&sha) {
712714
return Some(true);

0 commit comments

Comments
 (0)