diff --git a/zns-daemon/src/handlers/update/authenticate.rs b/zns-daemon/src/handlers/update/authenticate.rs index 23ae129..bc22903 100644 --- a/zns-daemon/src/handlers/update/authenticate.rs +++ b/zns-daemon/src/handlers/update/authenticate.rs @@ -21,7 +21,11 @@ pub async fn authenticate( //TODO: panic? subtract let username = &zone[zone.len() - Config::get().authoritative_zone.len() - 1]; - let ssh_verified = validate_ssh(username, sig).await.is_ok_and(|b| b); + let ssh_verified = validate_ssh(username, sig) + .await + .map_err(|e| ZNSError::Servfail { + message: e.to_string(), + })?; if ssh_verified { Ok(true) @@ -49,7 +53,13 @@ async fn validate_ssh(username: &String, sig: &Sig) -> Result>() .await? .iter() - .any(|key| sig.verify_ssh(&key).is_ok_and(|b| b))) + .any(|key| match sig.verify_ssh(&key) { + Ok(value) => value, + Err(e) => { + eprintln!("{}", e); + false + } + })) } async fn validate_dnskey( @@ -66,7 +76,12 @@ async fn validate_dnskey( .iter() .any(|rr| { let mut reader = Reader::new(&rr.rdata); - DNSKeyRData::from_bytes(&mut reader) - .is_ok_and(|dnskey| sig.verify_dnskey(dnskey).is_ok_and(|b| b)) + DNSKeyRData::from_bytes(&mut reader).is_ok_and(|dnskey| match sig.verify_dnskey(dnskey) { + Ok(value) => value, + Err(e) => { + eprintln!("{}", e); + false + } + }) })) } diff --git a/zns-daemon/src/handlers/update/mod.rs b/zns-daemon/src/handlers/update/mod.rs index 5e5293f..57f9ae2 100644 --- a/zns-daemon/src/handlers/update/mod.rs +++ b/zns-daemon/src/handlers/update/mod.rs @@ -54,10 +54,7 @@ impl ResponseHandler for UpdateHandler { if last.is_some() && last.unwrap()._type == Type::Type(RRType::SIG) { let sig = Sig::new(last.unwrap(), raw)?; - if !authenticate::authenticate(&sig, &zone.qname, connection) - .await - .is_ok_and(|x| x) - { + if !authenticate::authenticate(&sig, &zone.qname, connection).await? { return Err(ZNSError::Refused { message: "Unable to verify authentication".to_string(), }); diff --git a/zns/src/errors.rs b/zns/src/errors.rs index a0ad105..45cd89d 100644 --- a/zns/src/errors.rs +++ b/zns/src/errors.rs @@ -10,7 +10,7 @@ pub enum ZNSError { Reader { message: String }, #[error("Key Error: {message:?}")] Key { message: String }, - #[error("Server error")] + #[error("Server error: {message:?}")] Servfail { message: String }, #[error("DNS Query Format Error: {message:?}")] Formerr { message: String },