Add ssh-agent native auth
ci / test (push) Has been cancelled
ci / remote-bench (push) Has been cancelled

This commit is contained in:
DuProcess
2026-06-13 15:21:21 -04:00
parent e7f3679fc1
commit 55a0fc1ab4
5 changed files with 484 additions and 14 deletions
+35 -2
View File
@@ -19,6 +19,7 @@ use dosh::protocol::{
Resize, ResumeRequest, SERVER_TO_CLIENT, TicketAttachBody, TicketAttachEnvelope,
TicketAttachOkEnvelope,
};
use dosh::ssh_agent;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::fs;
@@ -899,8 +900,13 @@ async fn try_native_auth(
&hello,
&server_hello.hello,
)?;
let identity = load_first_native_identity(config, cli_identity, &ssh_config)?;
let auth = sign_user_auth(&identity, &hello, &server_hello.hello, Vec::new())?;
let auth = sign_native_user_auth(
config,
cli_identity,
&ssh_config,
&hello,
&server_hello.hello,
)?;
let mut pending_id = [0u8; 16];
pending_id.copy_from_slice(&server_hello.hello.auth_challenge[..16]);
let auth_body = protocol::to_body(&NativeUserAuthBody { auth })?;
@@ -953,6 +959,33 @@ async fn try_native_auth(
Ok((frame, cred))
}
fn sign_native_user_auth(
config: &dosh::config::ClientConfig,
cli_identity: Option<&Path>,
ssh_config: &SshConfig,
hello: &dosh::native::NativeClientHello,
server_hello: &dosh::native::NativeServerHello,
) -> Result<dosh::native::NativeUserAuth> {
let mut errors = Vec::new();
if config.use_ssh_agent {
match ssh_agent::sign_user_auth_with_agent(hello, server_hello, Vec::new()) {
Ok(auth) => return Ok(auth),
Err(err) => errors.push(format!("ssh-agent: {err:#}")),
}
}
match load_first_native_identity(config, cli_identity, ssh_config) {
Ok(identity) => sign_user_auth(&identity, hello, server_hello, Vec::new()),
Err(err) => {
errors.push(format!("identity files: {err:#}"));
Err(anyhow!(
"native auth found no usable key: {}",
errors.join("; ")
))
}
}
}
fn load_first_native_identity(
config: &dosh::config::ClientConfig,
cli_identity: Option<&Path>,