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, pub config: String,
} }
#[derive(Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
struct Config { struct Config {
secret: String, secret: String,
outdir: PathBuf, outdir: PathBuf,
disable_hmac_verify: bool,
} }
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
@ -44,6 +45,7 @@ struct Payload {
fn main() -> Result<(), Error> { fn main() -> Result<(), Error> {
let args = Opt::from_args(); let args = Opt::from_args();
let config: Config = serde_json::from_str(&args.config)?; let config: Config = serde_json::from_str(&args.config)?;
println!("{:?}", config);
let mut payload = String::new(); let mut payload = String::new();
io::stdin().read_to_string(&mut payload)?; io::stdin().read_to_string(&mut payload)?;
@ -51,6 +53,7 @@ fn main() -> Result<(), Error> {
let payload: Payload = serde_json::from_str(&payload)?; let payload: Payload = serde_json::from_str(&payload)?;
println!("processed payload: {}", payload.body); println!("processed payload: {}", payload.body);
if !config.disable_hmac_verify {
let secret = GenericArray::from_iter(config.secret.bytes()); let secret = GenericArray::from_iter(config.secret.bytes());
let mut mac = Hmac::<Sha1>::new(&secret); let mut mac = Hmac::<Sha1>::new(&secret);
mac.input(payload.body.as_bytes()); mac.input(payload.body.as_bytes());
@ -69,6 +72,7 @@ fn main() -> Result<(), Error> {
let left = SecStr::from(format!("sha1={}", signature)); let left = SecStr::from(format!("sha1={}", signature));
let right = SecStr::from(auth.bytes().collect::<Vec<_>>()); let right = SecStr::from(auth.bytes().collect::<Vec<_>>());
assert!(left == right, "HMAC signature didn't match"); assert!(left == right, "HMAC signature didn't match");
}
println!("gonna clone it to {:?}", config.outdir); println!("gonna clone it to {:?}", config.outdir);
Ok(()) Ok(())

View file

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