Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle pubkey blob in sign call being SSH cert #43

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions rustica-agent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,14 @@ impl SshAgentHandler for Handler {
_flags: u32,
) -> Result<Response, AgentError> {
trace!("Sign call");

// Extract the pubkey fingerprint from either the SSH pubkey or the SSH cert
let fingerprint = match (Certificate::from_bytes(&pubkey), PublicKey::from_bytes(&pubkey)) {
(Ok(cert), _) => cert.key.fingerprint(),
(_, Ok(pubkey)) => pubkey.fingerprint(),
_ => return Err(AgentError::from("Invalid key blob")),
};

// Tri check to find how to sign the request. Since starting rustica with a file based
// key is the same process as keys added afterwards, we do this to prevent duplication
// of the private key based signing code.
Expand Down Expand Up @@ -334,7 +342,7 @@ impl SshAgentHandler for Handler {
return Ok(Response::SignResponse { signature });
} else if let Signatory::Direct(privkey) = &self.signatory {
// Don't sign requests if the requested key does not match the signatory
if privkey.pubkey.encode() != pubkey {
if privkey.pubkey.fingerprint() != fingerprint {
return Err(AgentError::from("No such key"));
}

Expand All @@ -348,11 +356,12 @@ impl SshAgentHandler for Handler {
println!("Yubikey Fetch Certificate Error: {e}");
AgentError::from("Yubikey fetch certificate error")
})?
.encode()
!= pubkey
.fingerprint()
!= fingerprint
{
return Err(AgentError::from("No such key"));
}

// Since we are using the Yubikey for a signing operation the only time they
// won't have to tap here is if they are using cached keys and this is right after
// a secure Rustica tap. In most cases, we'll need to send this, rarely, it'll be
Expand Down
Loading