1
1
use brotli:: enc:: BrotliEncoderParams ;
2
2
use brotli:: BrotliCompress ;
3
3
use hmac:: { Hmac , Mac } ;
4
+ use sha2:: Sha256 ;
4
5
use std:: collections:: HashMap ;
5
6
use std:: net:: SocketAddr ;
6
7
use std:: path:: Path ;
@@ -18,7 +19,6 @@ use log::{debug, error, info};
18
19
use parking_lot:: { Mutex , RwLock } ;
19
20
use serde:: de:: DeserializeOwned ;
20
21
use serde:: Serialize ;
21
- use sha1:: Sha1 ;
22
22
use uuid:: Uuid ;
23
23
24
24
pub use crate :: api:: {
@@ -690,23 +690,25 @@ fn not_found() -> http::Response<hyper::Body> {
690
690
}
691
691
692
692
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 ( ) ) ;
695
697
let gh_header = match gh_header {
696
698
Some ( v) => v,
697
699
None => return false ,
698
700
} ;
699
- verify_gh_sig ( config, & gh_header, body) . unwrap_or ( false )
701
+ verify_gh_sig ( config, gh_header, body) . unwrap_or ( false )
700
702
}
701
703
702
704
fn verify_gh_sig ( cfg : & Config , header : & str , body : & [ u8 ] ) -> Option < bool > {
703
- type HmacSha1 = Hmac < Sha1 > ;
705
+ type HmacSha256 = Hmac < Sha256 > ;
704
706
705
707
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 ( ) )
707
709
. expect ( "HMAC can take key of any size" ) ;
708
710
mac. update ( body) ;
709
- let sha = header. get ( 5 .. ) ?; // strip sha1=
711
+ let sha = header. strip_prefix ( "sha256=" ) ?;
710
712
let sha = hex:: decode ( sha) . ok ( ) ?;
711
713
if let Ok ( ( ) ) = mac. verify_slice ( & sha) {
712
714
return Some ( true ) ;
0 commit comments