Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
Small improvements to signer/agent
Alexis Sellier committed 3 years ago
commit 41f53f3faeaac73855f6060c1f9bd1e50803dbcc
parent 092ccfdcbc895a73fd5c0efce378fbd5165b4386
3 files changed +21 -7
modified radicle-crypto/src/ssh/agent.rs
@@ -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 {
modified radicle-tools/src/rad-agent.rs
@@ -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(())
modified radicle/src/profile.rs
@@ -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 {