Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
ssh: Use winpipe for SSH agent on Windows
✗ CI failure Lorenz Leutgeb committed 11 months ago
commit aee3975bddafd95577393cf6ded50c2a0980c58b
parent da8aa78134f638760be28a60c1064e15f003ba40
1 failed 1 pending (2 total) View logs
4 files changed +49 -16
modified crates/radicle-crypto/Cargo.toml
@@ -32,6 +32,9 @@ ssh-key = { workspace = true, features = ["std", "encryption", "getrandom"], opt
thiserror = { workspace = true }
zeroize = { workspace = true }

+
[target.'cfg(windows)'.dependencies]
+
winpipe = { workspace = true }
+

[dev-dependencies]
fastrand = { workspace = true }
qcheck = { workspace = true }
modified crates/radicle-crypto/src/ssh/agent.rs
@@ -6,10 +6,10 @@ pub use radicle_ssh::{self as ssh, agent::client::ClientStream};

use crate::{PublicKey, SecretKey, Signature, Signer, SignerError};

-
#[cfg(not(unix))]
-
pub use std::net::TcpStream as Stream;
#[cfg(unix)]
-
pub use std::os::unix::net::UnixStream as Stream;
+
use std::os::unix::net::UnixStream as Stream;
+
#[cfg(windows)]
+
use winpipe::WinStream as Stream;

use super::ExtendedSignature;

modified crates/radicle-ssh/Cargo.toml
@@ -18,3 +18,6 @@ byteorder = { workspace = true }
log = { workspace = true }
thiserror = { workspace = true }
zeroize = { workspace = true }
+

+
[target.'cfg(windows)'.dependencies]
+
winpipe = { workspace = true }

\ No newline at end of file
modified crates/radicle-ssh/src/agent/client.rs
@@ -1,14 +1,17 @@
use std::fmt;
-
use std::io::{Read, Write};
use std::ops::DerefMut;
-
use std::os::unix::net::UnixStream;
use std::path::Path;
use std::str::FromStr;

-
use byteorder::{BigEndian, ByteOrder, WriteBytesExt};
+
#[cfg(unix)]
+
use std::os::unix::net::UnixStream;
+

+
#[cfg(windows)]
+
use winpipe::WinStream;
+

+
use byteorder::{BigEndian, WriteBytesExt};
use log::*;
use thiserror::Error;
-
use zeroize::Zeroize as _;

use crate::agent::msg;
use crate::agent::Constraint;
@@ -372,21 +375,40 @@ impl<S: ClientStream> AgentClient<S> {
    }
}

-
#[cfg(not(unix))]
-
impl ClientStream for TcpStream {
-
    fn connect_uds<P>(_: P) -> Result<AgentClient<Self>, Error>
+
#[cfg(windows)]
+
impl ClientStream for WinStream {
+
    fn connect<P>(path: P) -> Result<AgentClient<Self>, Error>
    where
        P: AsRef<Path> + Send,
    {
-
        Err(Error::AgentFailure)
-
    }
+
        let stream = WinStream::connect(path)?;

-
    fn read_response(&mut self, _: &mut Buffer) -> Result<(), Error> {
-
        Err(Error::AgentFailure)
+
        Ok(AgentClient { stream })
    }

-
    fn connect_env() -> Result<AgentClient<Self>, Error> {
-
        Err(Error::AgentFailure)
+
    fn request(&mut self, req: &[u8]) -> Result<Buffer, Error> {
+
        use std::io::{Read, Write};
+

+
        use byteorder::ByteOrder as _;
+
        use zeroize::Zeroize as _;
+

+
        let mut resp = Buffer::default();
+

+
        // Write the message
+
        self.write_all(req)?;
+
        self.flush()?;
+

+
        // Read the length
+
        resp.resize(4, 0);
+
        self.read_exact(&mut resp)?;
+

+
        // Read the rest of the buffer
+
        let len = BigEndian::read_u32(&resp) as usize;
+
        resp.zeroize();
+
        resp.resize(len, 0);
+
        self.read_exact(&mut resp)?;
+

+
        Ok(resp)
    }
}

@@ -402,6 +424,11 @@ impl ClientStream for UnixStream {
    }

    fn request(&mut self, msg: &[u8]) -> Result<Buffer, Error> {
+
        use std::io::{Read, Write};
+

+
        use byteorder::ByteOrder as _;
+
        use zeroize::Zeroize as _;
+

        let mut resp = Buffer::default();

        // Write the message