fix constant panics when keystore is weird

This commit is contained in:
core 2023-08-03 11:30:50 -04:00
parent 750aabc83c
commit afbd1d2ba0
Signed by: core
GPG Key ID: FDBF740DADDCEECF
1 changed files with 16 additions and 13 deletions

View File

@ -70,13 +70,11 @@ pub async fn dnclient(
let client_keys = host_in_ks let client_keys = host_in_ks
.client_keys .client_keys
.iter() .iter()
.find(|u| u.id == req.counter as u64) .find(|u| u.id == req.counter as u64);
.unwrap();
let client_keys_2 = host_in_ks let client_keys_2 = host_in_ks
.client_keys .client_keys
.iter() .iter()
.find(|u| u.id == host_in_ks.current_client_key) .find(|u| u.id == host_in_ks.current_client_key);;
.unwrap();
let signature = match Signature::from_slice(&req.signature) { let signature = match Signature::from_slice(&req.signature) {
Ok(sig) => sig, Ok(sig) => sig,
@ -92,15 +90,20 @@ pub async fn dnclient(
} }
}; };
if client_keys let mut valid = false;
.ed_pub
.verify(req.message.as_bytes(), &signature) if let Some(client_keys) = client_keys {
.is_err() if client_keys.ed_pub.verify(req.message.as_bytes(), &signature).is_ok() {
&& client_keys_2 valid = true;
.ed_pub }
.verify(req.message.as_bytes(), &signature) }
.is_err() if let Some(client_keys_2) = client_keys_2 {
{ if client_keys_2.ed_pub.verify(req.message.as_bytes(), &signature).is_ok() {
valid = true;
}
}
if !valid {
// Be intentionally vague as the message is invalid. // Be intentionally vague as the message is invalid.
warn!("! invalid signature from {}", host); warn!("! invalid signature from {}", host);
return HttpResponse::Unauthorized().json(vec![APIError { return HttpResponse::Unauthorized().json(vec![APIError {