feat: update ssh agent

This commit is contained in:
2025-05-25 23:17:46 +08:00
parent f870c07387
commit 5b3e0bc8cb
3 changed files with 17 additions and 4 deletions

1
Cargo.lock generated
View File

@@ -562,6 +562,7 @@ dependencies = [
"spki 0.7.3",
"ssh-agent",
"ssh-agent-lib",
"ssh-encoding",
"ssh-key",
"sshcerts",
"swift-secure-enclave-tool-rs",

View File

@@ -65,5 +65,6 @@ external-command-rs = "0.1.1"
ssh-agent-lib = { version = "0.5.1" }
ssh-key = { version = "0.6", features = ["ecdsa"] }
tokio = "1.45.1"
ssh-encoding = { version = "0.2.0", features = ["alloc"] }
#lazy_static = "1.4.0"
#ctap-hid-fido2 = "2.1.3"

View File

@@ -4,11 +4,13 @@ use std::path::PathBuf;
use clap::{App, Arg, ArgMatches, SubCommand};
use crate::ecdsautil::{generate_ecdsa_keypair, EcdsaAlgorithm};
use crate::util::base64_encode;
use rust_util::util_clap::{Command, CommandError};
use rust_util::XResult;
use ssh_agent_lib::agent::{listen, Session};
use ssh_agent_lib::error::AgentError;
use ssh_agent_lib::proto::{Identity, SignRequest};
use ssh_agent_lib::proto::{Extension, Identity, SignRequest};
use ssh_agent_lib::ssh_encoding::Encode;
use ssh_agent_lib::ssh_key::public::KeyData;
use ssh_agent_lib::ssh_key::{Algorithm, Signature};
use tokio::net::UnixListener as Listener;
@@ -35,12 +37,16 @@ impl Session for MySshAgent {
debugging!("request_identities");
// let p256_private_key_d = ecdsautil::parse_p256_private_key(&self.private_key_pem).unwrap();
let public_key_point = hex::decode("0474b7b8dcac7587afc8c461e96d713d05a4caae9dc4188924697fcb8dec2b8001d337e9ff4da1fb30042fef53375bde0cbe4964c71298b9d56bd9131c347119f3").unwrap();
Ok(vec![Identity {
let identity = Identity {
pubkey: KeyData::Ecdsa(
ssh_key::public::EcdsaPublicKey::from_sec1_bytes(&public_key_point).unwrap(),
),
comment: "".to_string(),
}])
comment: "test".to_string(),
};
let mut writer = vec![];
identity.pubkey.encode(&mut writer).unwrap();
println!("{}", base64_encode(&writer));
Ok(vec![identity])
}
async fn sign(&mut self, request: SignRequest) -> Result<Signature, AgentError> {
@@ -53,6 +59,11 @@ impl Session for MySshAgent {
)
.map_err(AgentError::other)?)
}
async fn extension(&mut self, extension: Extension) -> Result<Option<Extension>, AgentError> {
debugging!("extension: {:?}", extension);
Ok(None)
}
}
pub struct CommandImpl;