opt to skip the check for now

This commit is contained in:
Michael 2018-08-16 15:18:45 +00:00
parent 6b6087c4e9
commit e3ed6d8517
2 changed files with 22 additions and 17 deletions

View file

@ -29,10 +29,11 @@ struct Opt {
pub config: String,
}
#[derive(Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize)]
struct Config {
secret: String,
outdir: PathBuf,
disable_hmac_verify: bool,
}
#[derive(Serialize, Deserialize)]
@ -44,6 +45,7 @@ struct Payload {
fn main() -> Result<(), Error> {
let args = Opt::from_args();
let config: Config = serde_json::from_str(&args.config)?;
println!("{:?}", config);
let mut payload = String::new();
io::stdin().read_to_string(&mut payload)?;
@ -51,24 +53,26 @@ fn main() -> Result<(), Error> {
let payload: Payload = serde_json::from_str(&payload)?;
println!("processed payload: {}", payload.body);
let secret = GenericArray::from_iter(config.secret.bytes());
let mut mac = Hmac::<Sha1>::new(&secret);
mac.input(payload.body.as_bytes());
let signature = mac.result()
.code()
.into_iter()
.map(|b| format!("{:02x}", b))
.collect::<Vec<_>>()
.join("");
if !config.disable_hmac_verify {
let secret = GenericArray::from_iter(config.secret.bytes());
let mut mac = Hmac::<Sha1>::new(&secret);
mac.input(payload.body.as_bytes());
let signature = mac.result()
.code()
.into_iter()
.map(|b| format!("{:02x}", b))
.collect::<Vec<_>>()
.join("");
let auth = payload
.headers
.get("x-hub-signature")
.ok_or(err_msg("Missing auth header"))?;
let auth = payload
.headers
.get("x-hub-signature")
.ok_or(err_msg("Missing auth header"))?;
let left = SecStr::from(format!("sha1={}", signature));
let right = SecStr::from(auth.bytes().collect::<Vec<_>>());
assert!(left == right, "HMAC signature didn't match");
let left = SecStr::from(format!("sha1={}", signature));
let right = SecStr::from(auth.bytes().collect::<Vec<_>>());
assert!(left == right, "HMAC signature didn't match");
}
println!("gonna clone it to {:?}", config.outdir);
Ok(())

View file

@ -119,6 +119,7 @@ where
}
}
}
println!("Done loading config.");
}
fn watch<P>(root: P) -> notify::Result<()>