From: Ian Jackson Date: Tue, 1 Jun 2021 19:30:48 +0000 (+0100) Subject: sshkeys internal errors: Do not share with client X-Git-Tag: otter-0.7.0~134 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=3127c3bf7679e1af537087c9f51a3b854aea1023;p=otter.git sshkeys internal errors: Do not share with client Signed-off-by: Ian Jackson --- diff --git a/src/error.rs b/src/error.rs index 4d5cc202..4c097429 100644 --- a/src/error.rs +++ b/src/error.rs @@ -64,6 +64,8 @@ pub enum InternalError { ZCoordinateOverflow(#[from] zcoord::Overflow), #[error("Multiple errors occurred where only one could be reported")] Aggregated, + #[error("{0}")] + SshKeysManipError(#[from] sshkeys::AuthKeysManipError), } #[derive(Error,Copy,Clone,Debug,Serialize,Deserialize)] diff --git a/src/sshkeys.rs b/src/sshkeys.rs index 4fcef54e..21632935 100644 --- a/src/sshkeys.rs +++ b/src/sshkeys.rs @@ -74,6 +74,22 @@ pub struct KeySpec { pub nonce: sshkeys::Nonce, } +#[derive(Error,Copy,Clone,Debug,Hash,Serialize,Deserialize)] +#[error("ssh authorized_keys manipulation failed")] +pub struct AuthKeysManipError { } +impl From for AuthKeysManipError { + fn from(ae: anyhow::Error) -> AuthKeysManipError { + error!("authorized_keys manipulation error: {}: {:?}", + &config().authorized_keys, ae); + AuthKeysManipError { } + } +} +impl From for MgmtError { + fn from(akme: AuthKeysManipError) -> MgmtError { + IE::from(akme).into() + } +} + mod veneer { // openssh_keys's API is a little odd. We make our own mini-API. use crate::prelude::*; @@ -428,7 +444,7 @@ impl Global { }) } - #[throws(InternalError)] + #[throws(AuthKeysManipError)] fn write_keys(&self, w: &mut BufWriter) { for (id, key) in &self.keys { let fp = match key.fp { Some(Ok(ref fp)) => fp, _ => continue }; @@ -445,7 +461,7 @@ impl Global { // Caller should make sure accounts are saved first, to avoid // getting the authkeys_dirty bit wrong. - #[throws(InternalError)] + #[throws(AuthKeysManipError)] fn rewrite_authorized_keys(&mut self) { let config = config(); let path = &config.authorized_keys;