Skip to content

Commit

Permalink
Client checks pubkey in challenge before signing
Browse files Browse the repository at this point in the history
  • Loading branch information
timweri committed Nov 10, 2023
1 parent 2f860c1 commit 15dc17c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rustica-agent/src/rustica/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct ServerError {
pub enum RefreshError {
TransportError,
SigningError,
ServerChallengeNotForClientKey,
UnsupportedMode,
InvalidUri,
ConfigurationError(String),
Expand All @@ -25,6 +26,7 @@ impl fmt::Display for RefreshError {
match *self {
RefreshError::ConfigurationError(ref err) => write!(f, "Configuration is invalid: {}", err),
RefreshError::TransportError => write!(f, "Transport Error. Generally a TLS issue"),
RefreshError::ServerChallengeNotForClientKey => write!(f, "Server challenge is for a key unknown to the client"),
RefreshError::SigningError => write!(f, "Signing or verification failed"),
RefreshError::UnsupportedMode => write!(f, "Attempted to use a curve or cipher not supported by rustica-agent"),
RefreshError::InvalidUri => write!(f, "Provided address of remote service was invalid"),
Expand Down
8 changes: 8 additions & 0 deletions rustica-agent/src/rustica/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ pub async fn complete_rustica_challenge(
SSHCertificate::from_string(&response.challenge).map_err(|_| RefreshError::SigningError)?;
challenge_certificate.signature_key = challenge_certificate.key.clone();

// We assert that the pubkey in the challenge belongs to the client
// This prevents a malicious Rustica server from tricking the client into signing a
// malicious SSH certificate for some unknown key.
if challenge_certificate.key.fingerprint().hash != ssh_pubkey.fingerprint().hash {
error!("The public key in the challenge doesn't match the client's public key");
return Err(RefreshError::ServerChallengeNotForClientKey);
}

let resigned_certificate = match signatory {
Signatory::Yubikey(signer) => {
let signature = signer
Expand Down

0 comments on commit 15dc17c

Please sign in to comment.