10
0
Fork 0
mirror of https://github.com/ZeusWPI/ZNS.git synced 2024-11-24 06:11:10 +01:00

better error printing

This commit is contained in:
Xander Bil 2024-08-21 16:50:33 +02:00
parent c1ab0cc953
commit 6ed4de8b44
No known key found for this signature in database
GPG key ID: EC9706B54A278598
3 changed files with 21 additions and 9 deletions

View file

@ -21,7 +21,11 @@ pub async fn authenticate(
//TODO: panic? subtract //TODO: panic? subtract
let username = &zone[zone.len() - Config::get().authoritative_zone.len() - 1]; 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 { if ssh_verified {
Ok(true) Ok(true)
@ -49,7 +53,13 @@ async fn validate_ssh(username: &String, sig: &Sig) -> Result<bool, reqwest::Err
.json::<Vec<String>>() .json::<Vec<String>>()
.await? .await?
.iter() .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( async fn validate_dnskey(
@ -66,7 +76,12 @@ async fn validate_dnskey(
.iter() .iter()
.any(|rr| { .any(|rr| {
let mut reader = Reader::new(&rr.rdata); let mut reader = Reader::new(&rr.rdata);
DNSKeyRData::from_bytes(&mut reader) DNSKeyRData::from_bytes(&mut reader).is_ok_and(|dnskey| match sig.verify_dnskey(dnskey) {
.is_ok_and(|dnskey| sig.verify_dnskey(dnskey).is_ok_and(|b| b)) Ok(value) => value,
Err(e) => {
eprintln!("{}", e);
false
}
})
})) }))
} }

View file

@ -54,10 +54,7 @@ impl ResponseHandler for UpdateHandler {
if last.is_some() && last.unwrap()._type == Type::Type(RRType::SIG) { if last.is_some() && last.unwrap()._type == Type::Type(RRType::SIG) {
let sig = Sig::new(last.unwrap(), raw)?; let sig = Sig::new(last.unwrap(), raw)?;
if !authenticate::authenticate(&sig, &zone.qname, connection) if !authenticate::authenticate(&sig, &zone.qname, connection).await? {
.await
.is_ok_and(|x| x)
{
return Err(ZNSError::Refused { return Err(ZNSError::Refused {
message: "Unable to verify authentication".to_string(), message: "Unable to verify authentication".to_string(),
}); });

View file

@ -10,7 +10,7 @@ pub enum ZNSError {
Reader { message: String }, Reader { message: String },
#[error("Key Error: {message:?}")] #[error("Key Error: {message:?}")]
Key { message: String }, Key { message: String },
#[error("Server error")] #[error("Server error: {message:?}")]
Servfail { message: String }, Servfail { message: String },
#[error("DNS Query Format Error: {message:?}")] #[error("DNS Query Format Error: {message:?}")]
Formerr { message: String }, Formerr { message: String },