11use brotli:: enc:: BrotliEncoderParams ;
22use brotli:: BrotliCompress ;
33use hmac:: { Hmac , Mac } ;
4+ use sha2:: Sha256 ;
45use std:: collections:: HashMap ;
56use std:: net:: SocketAddr ;
67use std:: path:: Path ;
@@ -18,7 +19,6 @@ use log::{debug, error, info};
1819use parking_lot:: { Mutex , RwLock } ;
1920use serde:: de:: DeserializeOwned ;
2021use serde:: Serialize ;
21- use sha1:: Sha1 ;
2222use uuid:: Uuid ;
2323
2424pub use crate :: api:: {
@@ -690,23 +690,25 @@ fn not_found() -> http::Response<hyper::Body> {
690690}
691691
692692fn 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
702704fn 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