Giter Site home page Giter Site logo

honzasp / makiko Goto Github PK

View Code? Open in Web Editor NEW
37.0 37.0 3.0 1.05 MB

Asynchronous SSH client library in pure Rust

Home Page: https://honzasp.github.io/makiko/

License: The Unlicense

Python 2.03% Rust 97.44% Dockerfile 0.53%
async rust ssh ssh-client ssh-client-library ssh-library tokio

makiko's People

Contributors

honzasp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

makiko's Issues

comparison to russh

This library looks really nice and im trying to compare it against russh.
I would appreciate a section in the readme that explains what differentiates makiko from russh.

One difference I can see is that russh also supports writing ssh servers.
I'm hoping that makiko focusing on writing clients makes it better for that.

Thanks!

SSH-level keep-alive support

I'm trying to use makiko to do some remote automation work where I need SSH port forwarding, but I'm having the issue where sometimes there are long periods between when the SSH channel is actually used, and so sometimes they end up having timed out by the time I need to use them again, which would require some moderately complex abstraction to be able to work around.

It would be nice if makiko instead supported SSH-level keep-alive ร  la OpenSSH's ServerAliveInterval/ServerAliveCountMax which send null packets through the encrypted channel.

shell execute empty stdout command will block the session receiver.

When I start the shell and execute a command with no output, such as 'cat empty.txt,' the session event receiver gets blocked and doesn't return empty stdout data.
`
let stream = TcpStream::connect("192.168.255.167:22").await?;

let config = makiko::ClientConfig::default_compatible_less_secure();

let (client, mut client_rx, client_fut) = makiko::Client::open(stream, config)?;
let h1 = tokio::spawn(async move {
    let e = client_fut.await;
});
let h2 = tokio::spawn(async move {
    loop {
        // Wait for the next event.
        let event = client_rx.recv().await;
        let Ok(Some(event)) = event else { break };
        match event {
            // Handle the server public key: for now, we just accept all keys, but this makes
            // us susceptible to man-in-the-middle attacks!
            makiko::ClientEvent::ServerPubkey(_pubkey, accept) => {
                // println!("Server pubkey type {}, fingerprint {}",pubkey.type_str(),pubkey.fingerprint());
                accept.accept();
            }
            makiko::ClientEvent::AuthBanner(b) => {
                println!("{:?}", b);
            }
            _ => {}
        }
    }
});
let r = client.auth_password("root".into(), "123456".into()).await;
println!("{:?}",r);
let channel_config = makiko::ChannelConfig::default();
let (session, mut session_rx) = client.open_session(channel_config).await?;
let session_wait = tokio::spawn(async move {
    loop {
        // Wait for the next event.
        let event = session_rx
            .recv()
            .await.unwrap();
        println!("{:?}",event);
        // Exit the loop when the session has closed.
        let Some(event) = event else {
            break;
        };
    }
});
let r  = session.shell().unwrap().ignore();
session.send_stdin(Bytes::copy_from_slice(b"ls -hl\n")).await?;
session.send_stdin(Bytes::copy_from_slice(b"echo test > test.txt\n")).await?;
session.send_stdin(Bytes::copy_from_slice(b"cat empty.txt\n")).await?;
let r = session_wait.await?;
println!("finished");`

Cannot build on rust 1.70.0

  1. Upgrade rust to latest release 1.70.0
  2. Clone makiko or use it as dependency.
  3. Cargo build, errors:
error: `box_syntax` has been removed
   --> /home/york/.cargo/registry/src/index.crates.io-6f17d22bba15001f/guard-0.5.1/src/lib.rs:426:20
    |
426 |         let foo = (box 42, [1, 2, 3]);
    |                    ^^^^^^
    |
help: use `Box::new()` instead
    |
426 |         let foo = (Box::new(42), [1, 2, 3]);
    |                    ~~~~~~~~~~~~

AlgoNegotiateError

client_fut rst Err(AlgoNegotiate(AlgoNegotiateError { algo_name: "key exchange", our_algos: ["curve25519-sha256", "[email protected]"], their_algos: ["diffie-hellman-group14-sha1", "ecdh-sha2-nistp256", "ecdh-sha2-nistp384", "ecdh-sha2-nistp521"] })),
does'nt support "diffie-hellman-group14-sha1" yet?

Fails to connect to AWS EC2 instance

I ran this code against an amazon EC2 instance running ubuntu.

        let (client, mut client_rx, client_fut) = Client::open(
            tokio::net::TcpStream::connect((address, 22)).await.unwrap(),
            ClientConfig::default(),
        )
        .unwrap();

        tokio::task::spawn(async move {
            if let Err(err) = client_fut.await {
                tracing::error!("Error while driving ssh connection: {err}");
            }
        });

        tokio::task::spawn(async move {
            loop {
                // Wait for the next event.
                let event = client_rx
                    .recv()
                    .await
                    .expect("Error while receiving client event");

                // Normally a client would perform TOFU authentication (known_hosts file) against the server here.
                // But that would be pointless for us since we only connect to each server once.

                if event.is_none() {
                    // connection is closed
                    return;
                }
            }
        });

        let privkey = makiko::keys::decode_pem_privkey_nopass(private_key.as_bytes())
            .expect("Could not decode a private key from PEM")
            .privkey()
            .cloned()
            .expect("Private key is encrypted");

        let auth_res = client
            .auth_pubkey("ubuntu".to_owned(), privkey, &SSH_ED25519)
            .await
            .expect("Error when trying to authenticate");

I can connect to this instance fine with russh and I am passing in the same public ip and private ED25519 key that I use with russh.
The final .expect fails with: 'Error when trying to authenticate: AuthAborted'
And I also get a tracing error: Error while driving ssh connection: server public key was not accepted

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.