Small improvements to signer/agent

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
Alexis Sellier 2022-11-03 13:29:20 +01:00
parent 092ccfdcbc
commit 41f53f3fae
No known key found for this signature in database
3 changed files with 21 additions and 7 deletions

View File

@ -28,6 +28,11 @@ impl Agent {
pub fn register(&mut self, key: &crypto::SecretKey) -> Result<(), ssh::Error> {
self.client.add_identity(&SecretKey::from(*key), &[])
}
/// Get a signer from this agent, given the public key.
pub fn signer(self, key: PublicKey) -> AgentSigner {
AgentSigner::new(self, key)
}
}
impl Deref for Agent {

View File

@ -1,4 +1,4 @@
use anyhow::anyhow;
use anyhow::{anyhow, Context as _};
use radicle::{crypto, crypto::ssh};
use std::io::prelude::*;
use std::{env, io};
@ -7,16 +7,20 @@ fn main() -> anyhow::Result<()> {
let profile = radicle::Profile::load()?;
let mut agent = ssh::agent::Agent::connect()?;
println!("({})", ssh::fmt::key(profile.id()));
println!("key: {}", ssh::fmt::key(profile.id()));
println!("hash: {}", ssh::fmt::fingerprint(profile.id()));
match env::args().nth(1).as_deref() {
Some("add") => {
print!("passphrase: ");
io::stdout().flush()?;
let mut passphrase = String::new();
io::stdin().lock().read_line(&mut passphrase)?;
let secret = profile
.keystore
.secret_key(&passphrase)?
.secret_key(passphrase.trim())?
.ok_or_else(|| anyhow!("Key not found in {:?}", profile.keystore.path()))?;
agent.register(&secret)?;
@ -34,7 +38,7 @@ fn main() -> anyhow::Result<()> {
let mut stdin = Vec::new();
io::stdin().read_to_end(&mut stdin)?;
let sig = agent.sign(profile.id(), &stdin)?;
let sig = agent.sign(profile.id(), &stdin).context("Signing failed")?;
let sig = crypto::Signature::from(sig);
println!("{}", &sig);
@ -42,7 +46,13 @@ fn main() -> anyhow::Result<()> {
Some(other) => {
anyhow::bail!("Unknown command `{}`", other);
}
None => {}
None => {
if agent.signer(profile.public_key).is_ready()? {
println!("ready: yes");
} else {
println!("ready: no");
}
}
}
Ok(())

View File

@ -100,8 +100,7 @@ impl Profile {
pub fn signer(&self) -> Result<AgentSigner, Error> {
match Agent::connect() {
Ok(agent) => {
let signer = AgentSigner::new(agent, self.public_key);
let signer = agent.signer(self.public_key);
if signer.is_ready()? {
Ok(signer)
} else {