This commit is contained in:
nora 2024-08-22 21:17:51 +02:00
parent 3f0b367c39
commit 7ac2ef4194
4 changed files with 41 additions and 8 deletions

View file

@ -9,6 +9,11 @@ use tracing::{debug, trace};
/// A message to send to the byte stream. /// A message to send to the byte stream.
pub enum Request { pub enum Request {
AddIdentity {
key_type: String,
key_contents: Vec<u8>,
key_comment: String,
},
RemoveAllIdentities, RemoveAllIdentities,
ListIdentities, ListIdentities,
Sign { Sign {
@ -33,6 +38,16 @@ impl Request {
pub fn to_bytes(&self) -> Vec<u8> { pub fn to_bytes(&self) -> Vec<u8> {
let mut p = Writer::new(); let mut p = Writer::new();
match self { 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::RemoveAllIdentities => p.u8(numbers::SSH_AGENTC_REMOVE_ALL_IDENTITIES),
Self::ListIdentities => p.u8(numbers::SSH_AGENTC_REQUEST_IDENTITIES), Self::ListIdentities => p.u8(numbers::SSH_AGENTC_REQUEST_IDENTITIES),
Self::Sign { 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<()> { pub async fn remove_all_identities(&mut self) -> eyre::Result<()> {
self.send(Request::RemoveAllIdentities).await?; self.send(Request::RemoveAllIdentities).await?;
self.generic_response().await self.generic_response().await

View file

@ -1,7 +0,0 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACDpK6HZbsijDttnop9lQyLLGXZi7lS5Hb3bY7DKMDC1vAAAAIhd37wfXd+8
HwAAAAtzc2gtZWQyNTUxOQAAACDpK6HZbsijDttnop9lQyLLGXZi7lS5Hb3bY7DKMDC1vA
AAAEBCev7X+rchYbMmzYfiyBzZhV/RaZZhYh+MR4/Ktcu0l+krodluyKMO22ein2VDIssZ
dmLuVLkdvdtjsMowMLW8AAAAA3V3dQEC
-----END OPENSSH PRIVATE KEY-----

View file

@ -1 +0,0 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOkrodluyKMO22ein2VDIssZdmLuVLkdvdtjsMowMLW8 uwu

View file

@ -13,6 +13,11 @@ struct Args {
#[derive(clap::Subcommand, Debug)] #[derive(clap::Subcommand, Debug)]
enum Subcommand { 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 /// Remove all identities from the agent, SSH_AGENTC_REMOVE_ALL_IDENTITIES
RemoveAllIdentities, RemoveAllIdentities,
/// List all identities in the agent, SSH_AGENTC_REQUEST_IDENTITIES /// 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?; let mut agent = ssh_agent_client::SocketAgentConnection::from_env().await?;
match args.command { 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 => { Subcommand::RemoveAllIdentities => {
agent.remove_all_identities().await?; agent.remove_all_identities().await?;
println!("Removed all identities from the agent"); println!("Removed all identities from the agent");