chiark / gitweb /
sshkeys internal errors: Do not share with client
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 1 Jun 2021 19:30:48 +0000 (20:30 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 1 Jun 2021 19:31:17 +0000 (20:31 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/error.rs
src/sshkeys.rs

index 4d5cc202f2ca202a2d8817c2fa5cb465f6ceb4bb..4c097429a8aeee681ab6f6ccbfd6508e96492af8 100644 (file)
@@ -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)]
index 4fcef54e1b6d84b3be56979986869962978fefcd..21632935e6bdf6befa63191e5716e8b093e07426 100644 (file)
@@ -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<anyhow::Error> for AuthKeysManipError {
+  fn from(ae: anyhow::Error) -> AuthKeysManipError {
+    error!("authorized_keys manipulation error: {}: {:?}",
+           &config().authorized_keys, ae);
+    AuthKeysManipError { }
+  }
+}
+impl From<AuthKeysManipError> 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<File>) {
     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;