diff --git a/ssh-agent-client/src/lib.rs b/ssh-agent-client/src/lib.rs index a76ea4c..7d85dcd 100644 --- a/ssh-agent-client/src/lib.rs +++ b/ssh-agent-client/src/lib.rs @@ -9,6 +9,11 @@ use tracing::{debug, trace}; /// A message to send to the byte stream. pub enum Request { + AddIdentity { + key_type: String, + key_contents: Vec, + key_comment: String, + }, RemoveAllIdentities, ListIdentities, Sign { @@ -33,6 +38,16 @@ impl Request { pub fn to_bytes(&self) -> Vec { let mut p = Writer::new(); match self { + Self::AddIdentity { + key_type, + key_contents, + key_comment, + } => { + p.u8(numbers::SSH_AGENTC_ADD_IDENTITY); + p.string(key_type.as_bytes()); + p.write(&key_contents); + p.string(key_comment.as_bytes()); + } Self::RemoveAllIdentities => p.u8(numbers::SSH_AGENTC_REMOVE_ALL_IDENTITIES), Self::ListIdentities => p.u8(numbers::SSH_AGENTC_REQUEST_IDENTITIES), Self::Sign { @@ -212,6 +227,21 @@ impl SocketAgentConnection { }) } + pub async fn add_identitity( + &mut self, + key_type: &str, + key_contents: &[u8], + key_comment: &str, + ) -> eyre::Result<()> { + self.send(Request::AddIdentity { + key_type: key_type.to_owned(), + key_contents: key_contents.to_owned(), + key_comment: key_comment.to_owned(), + }) + .await?; + self.generic_response().await + } + pub async fn remove_all_identities(&mut self) -> eyre::Result<()> { self.send(Request::RemoveAllIdentities).await?; self.generic_response().await diff --git a/ssh-agentctl/here b/ssh-agentctl/here deleted file mode 100644 index 0f32710..0000000 --- a/ssh-agentctl/here +++ /dev/null @@ -1,7 +0,0 @@ ------BEGIN OPENSSH PRIVATE KEY----- -b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW -QyNTUxOQAAACDpK6HZbsijDttnop9lQyLLGXZi7lS5Hb3bY7DKMDC1vAAAAIhd37wfXd+8 -HwAAAAtzc2gtZWQyNTUxOQAAACDpK6HZbsijDttnop9lQyLLGXZi7lS5Hb3bY7DKMDC1vA -AAAEBCev7X+rchYbMmzYfiyBzZhV/RaZZhYh+MR4/Ktcu0l+krodluyKMO22ein2VDIssZ -dmLuVLkdvdtjsMowMLW8AAAAA3V3dQEC ------END OPENSSH PRIVATE KEY----- diff --git a/ssh-agentctl/here.pub b/ssh-agentctl/here.pub deleted file mode 100644 index 63f938a..0000000 --- a/ssh-agentctl/here.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOkrodluyKMO22ein2VDIssZdmLuVLkdvdtjsMowMLW8 uwu diff --git a/ssh-agentctl/src/main.rs b/ssh-agentctl/src/main.rs index ce40f9a..68be4f6 100644 --- a/ssh-agentctl/src/main.rs +++ b/ssh-agentctl/src/main.rs @@ -13,6 +13,11 @@ struct Args { #[derive(clap::Subcommand, Debug)] enum Subcommand { + /// Add a new identity to the agent, SSH_AGENTC_ADD_IDENTITY + AddIdentity { + /// The path to the private key file + identity: PathBuf, + }, /// Remove all identities from the agent, SSH_AGENTC_REMOVE_ALL_IDENTITIES RemoveAllIdentities, /// List all identities in the agent, SSH_AGENTC_REQUEST_IDENTITIES @@ -46,6 +51,12 @@ async fn main() -> eyre::Result<()> { let mut agent = ssh_agent_client::SocketAgentConnection::from_env().await?; match args.command { + Subcommand::AddIdentity { identity } => { + let file = std::fs::read(&identity) + .wrap_err_with(|| format!("reading file {}", identity.display()))?; + let _ = file; + todo!("we need to parse and decrypt the key...") + } Subcommand::RemoveAllIdentities => { agent.remove_all_identities().await?; println!("Removed all identities from the agent");