10
0
Fork 0
mirror of https://github.com/ZeusWPI/ZNS.git synced 2024-11-27 22:51:12 +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
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<bool, reqwest::Err
.json::<Vec<String>>()
.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
}
})
}))
}

View file

@ -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(),
});

View file

@ -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 },