use clap::Parser;
use service_binding::Binding;
use ssh_agent_lib::{
agent::{bind, Agent, Session},
error::AgentError,
proto::Identity,
};
use ssh_key::public::KeyData;
use testresult::TestResult;
#[derive(Debug, Default)]
struct AgentSocketInfo {
comment: String,
}
#[ssh_agent_lib::async_trait]
impl Session for AgentSocketInfo {
async fn request_identities(&mut self) -> Result<Vec<Identity>, AgentError> {
Ok(vec![Identity {
pubkey: KeyData::Ed25519(ssh_key::public::Ed25519PublicKey([0; 32])),
comment: self.comment.clone(),
}])
}
}
#[cfg(unix)]
impl Agent<tokio::net::UnixListener> for AgentSocketInfo {
fn new_session(&mut self, socket: &tokio::net::UnixStream) -> impl Session {
Self {
comment: format!(
"unix: addr: {:?} cred: {:?}",
socket.peer_addr().unwrap(),
socket.peer_cred().unwrap()
),
}
}
}
impl Agent<tokio::net::TcpListener> for AgentSocketInfo {
fn new_session(&mut self, _socket: &tokio::net::TcpStream) -> impl Session {
Self {
comment: "tcp".into(),
}
}
}
#[cfg(windows)]
impl Agent<ssh_agent_lib::agent::NamedPipeListener> for AgentSocketInfo {
fn new_session(
&mut self,
_socket: &tokio::net::windows::named_pipe::NamedPipeServer,
) -> impl Session {
Self {
comment: "pipe".into(),
}
}
}
#[derive(Debug, Parser)]
struct Args {
#[clap(short = 'H', long)]
host: Binding,
}
#[tokio::main]
async fn main() -> TestResult {
env_logger::init();
let args = Args::parse();
bind(args.host.try_into()?, AgentSocketInfo::default()).await?;
Ok(())
}