opt to skip the check for now
This commit is contained in:
parent
6b6087c4e9
commit
e3ed6d8517
2 changed files with 22 additions and 17 deletions
|
@ -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,24 +53,26 @@ 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);
|
||||||
|
|
||||||
let secret = GenericArray::from_iter(config.secret.bytes());
|
if !config.disable_hmac_verify {
|
||||||
let mut mac = Hmac::<Sha1>::new(&secret);
|
let secret = GenericArray::from_iter(config.secret.bytes());
|
||||||
mac.input(payload.body.as_bytes());
|
let mut mac = Hmac::<Sha1>::new(&secret);
|
||||||
let signature = mac.result()
|
mac.input(payload.body.as_bytes());
|
||||||
.code()
|
let signature = mac.result()
|
||||||
.into_iter()
|
.code()
|
||||||
.map(|b| format!("{:02x}", b))
|
.into_iter()
|
||||||
.collect::<Vec<_>>()
|
.map(|b| format!("{:02x}", b))
|
||||||
.join("");
|
.collect::<Vec<_>>()
|
||||||
|
.join("");
|
||||||
|
|
||||||
let auth = payload
|
let auth = payload
|
||||||
.headers
|
.headers
|
||||||
.get("x-hub-signature")
|
.get("x-hub-signature")
|
||||||
.ok_or(err_msg("Missing auth header"))?;
|
.ok_or(err_msg("Missing auth header"))?;
|
||||||
|
|
||||||
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(())
|
||||||
|
|
|
@ -119,6 +119,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
println!("Done loading config.");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn watch<P>(root: P) -> notify::Result<()>
|
fn watch<P>(root: P) -> notify::Result<()>
|
||||||
|
|
Loading…
Reference in a new issue