Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
crypto: Guard `MemorySigner` against key mismatch
Lorenz Leutgeb committed 7 months ago
commit cc8eb7170b0e9c79a49696a7469f193e8225fee4
parent ed8b086045ee5d7bd1327f579de7861a1cf49e3b
1 file changed +6 -0
modified crates/radicle-crypto/src/ssh/keystore.rs
@@ -183,6 +183,8 @@ pub enum MemorySignerError {
    NotFound(PathBuf),
    #[error("invalid passphrase")]
    InvalidPassphrase,
+
    #[error("secret key does not match given public key")]
+
    KeyMismatch,
}

/// An in-memory signer that keeps its secret key internally
@@ -272,6 +274,10 @@ impl MemorySigner {
            })?
            .ok_or_else(|| MemorySignerError::NotFound(keystore.path().to_path_buf()))?;

+
        secret
+
            .validate_public_key(&public)
+
            .map_err(|_| MemorySignerError::KeyMismatch)?;
+

        Ok(Self { public, secret })
    }