Skip to content

Commit

Permalink
fix(external-ssh-signer): apply fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chirpcel committed Jan 6, 2025
1 parent ebd8fc1 commit 9d934d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion asyncgit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ rayon = "1.10"
rayon-core = "1.12"
scopetime = { path = "../scopetime", version = "0.1" }
serde = { version = "1.0", features = ["derive"] }
tempfile = "3"
thiserror = "1.0"
unicode-truncate = "1.0"
url = "2.5"
tempfile = "3"

[dev-dependencies]
env_logger = "0.11"
Expand Down
22 changes: 14 additions & 8 deletions asyncgit/src/sync/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,7 @@ impl SignBuilder {
signing_key: &str,
) -> Result<PathBuf, SignBuilderError> {
let key_path = PathBuf::from(signing_key);
if key_path.is_file() {
Ok(key_path)
} else if signing_key.starts_with("ssh-") {
if signing_key.starts_with("ssh-") {
use std::io::Write;
use tempfile::NamedTempFile;
let mut temp_file =
Expand All @@ -200,9 +198,7 @@ impl SignBuilder {
})?;
Ok(temp_file.1)
} else {
Err(SignBuilderError::SSHSigningKey(String::from(
"ssh key could not been resolved. Either the key is not a file or the key is not a valid public ssh key",
)))
Ok(key_path)
}
}
}
Expand Down Expand Up @@ -306,6 +302,10 @@ impl Sign for SSHSign {
.arg("-f")
.arg(&self.signing_key);

if &self.program == "ssh-keygen" {
cmd.arg("-P").arg("\"\"");
}

log::trace!("signing command: {cmd:?}");

let mut child = cmd
Expand All @@ -319,6 +319,8 @@ impl Sign for SSHSign {
.map_err(|e| SignError::WriteBuffer(e.to_string()))?;
drop(stdin);

//hllo

let output = child
.wait_with_output()
.map_err(|e| SignError::Output(e.to_string()))?;
Expand All @@ -332,11 +334,15 @@ impl Sign for SSHSign {
}

if !output.status.success() {
let error_msg = std::str::from_utf8(&output.stderr)
.unwrap_or("[error could not be read from stderr]");
if error_msg.contains("passphrase") {
return Err(SignError::Shellout(String::from("Currently, we only support unencrypted pairs of ssh keys in disk or ssh-agents")));
}
return Err(SignError::Shellout(format!(
"failed to sign data, program '{}' exited non-zero: {}",
&self.program,
std::str::from_utf8(&output.stderr)
.unwrap_or("[error could not be read from stderr]")
error_msg
)));
}

Expand Down

0 comments on commit 9d934d6

Please sign in to comment.