Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"read_ssh_id" issue #422

Closed
mkrueger opened this issue Dec 20, 2024 · 6 comments
Closed

"read_ssh_id" issue #422

mkrueger opened this issue Dec 20, 2024 · 6 comments

Comments

@mkrueger
Copy link

After connecting "russh::client::connect" seems to get stuck or error on "russh::client::connect"

Depending on the server I get either a disconnect:

[2024-12-20T15:23:01Z DEBUG russh::ssh_read] read_ssh_id: reading
[2024-12-20T15:23:02Z DEBUG russh::ssh_read] read 0
[2024-12-20T15:23:02Z DEBUG russh::ssh_read] Ok("")
[2024-12-20T15:23:02Z ERROR icy_term::ui::terminal_thread] run_update_thread::open_connection: Disconnected

Or:

[2024-12-20T15:26:04Z DEBUG russh::ssh_read] read_ssh_id: reading
[2024-12-20T15:26:08Z DEBUG russh::ssh_read] read 1
[2024-12-20T15:26:08Z DEBUG russh::ssh_read] Ok("S")
[2024-12-20T15:26:08Z DEBUG russh::ssh_read] bytes_read: 0
[2024-12-20T15:26:08Z DEBUG russh::ssh_read] read_ssh_id: reading
[2024-12-20T15:26:08Z DEBUG russh::ssh_read] read 64
[2024-12-20T15:26:08Z DEBUG russh::ssh_read] Ok("Standby.... Loading Fido Mailer\rThis might take a few moments...\r")
[2024-12-20T15:26:08Z DEBUG russh::ssh_read] bytes_read: 0
[2024-12-20T15:26:08Z DEBUG russh::ssh_read] read_ssh_id: reading
[2024-12-20T15:26:17Z DEBUG russh::ssh_read] read 1
[2024-12-20T15:26:17Z DEBUG russh::ssh_read] Ok("Standby.... Loading Fido Mailer\rThis might take a few moments...\r*")
[2024-12-20T15:26:17Z DEBUG russh::ssh_read] bytes_read: 0
[2024-12-20T15:26:17Z DEBUG russh::ssh_read] read_ssh_id: reading
[2024-12-20T15:26:17Z DEBUG russh::ssh_read] read 138
[2024-12-20T15:26:17Z DEBUG russh::ssh_read] Ok("Standby.... Loading Fido Mailer\rThis might take a few moments...\r**EMSI_REQA77E\r\u{11}\r\r* Address 1:2215/1701@fidonet.org Using BinkleyTerm-ST 3.18pl2\r\n\r\nSTar Fleet HQ welcomes you! <FidoNet>\r\n\rPlease press yo")
[2024-12-20T15:26:17Z DEBUG russh::ssh_read] bytes_read: 0
[2024-12-20T15:26:17Z DEBUG russh::ssh_read] read_ssh_id: reading
[2024-12-20T15:26:18Z DEBUG russh::ssh_read] read 28
[2024-12-20T15:26:18Z DEBUG russh::ssh_read] Ok("ur Escape key to ENERGIZE!.\r")
[2024-12-20T15:26:18Z DEBUG russh::ssh_read] bytes_read: 0
[2024-12-20T15:26:18Z DEBUG russh::ssh_read] read_ssh_id: reading
[2024-12-20T15:26:38Z DEBUG russh::ssh_read] read 1
[2024-12-20T15:26:38Z DEBUG russh::ssh_read] Ok("ur Escape key to ENERGIZE!.\r\r")
[2024-12-20T15:26:38Z DEBUG russh::ssh_read] bytes_read: 0
[2024-12-20T15:26:38Z DEBUG russh::ssh_read] read_ssh_id: reading
[2024-12-20T15:26:38Z DEBUG russh::ssh_read] read 26
[2024-12-20T15:26:38Z DEBUG russh::ssh_read] Ok("ur Escape key to ENERGIZE!.\r\r\nEnergizing.............\r\n")
[2024-12-20T15:26:38Z DEBUG russh::ssh_read] bytes_read: 0
[2024-12-20T15:26:38Z DEBUG russh::ssh_read] read_ssh_id: reading
[2024-12-20T15:26:40Z DEBUG russh::ssh_read] read 1
[2024-12-20T15:26:40Z DEBUG russh::ssh_read] Ok("\u{c}")
[2024-12-20T15:26:40Z DEBUG russh::ssh_read] bytes_read: 0
[2024-12-20T15:26:40Z DEBUG russh::ssh_read] read_ssh_id: reading
[2024-12-20T15:26:40Z DEBUG russh::ssh_read] read 121
[2024-12-20T15:26:40Z DEBUG russh::ssh_read] Ok("\u{c}\r\n                              === RATSoft / ST ===\r\n               by Steve Hughey, (c)1991-1995 R0dent Labs Software\r\n")
[2024-12-20T15:26:40Z DEBUG russh::ssh_read] bytes_read: 0
[2024-12-20T15:26:40Z DEBUG russh::ssh_read] read_ssh_id: reading
[2024-12-20T15:26:40Z DEBUG russh::ssh_read] read 58
[2024-12-20T15:26:40Z DEBUG russh::ssh_read] Ok("                       version 2.1c [10/21/95 - 12:16pm]\r\n")
[2024-12-20T15:26:40Z DEBUG russh::ssh_read] bytes_read: 0
[2024-12-20T15:26:40Z DEBUG russh::ssh_read] read_ssh_id: reading
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] read 1
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] Ok(" ")
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] bytes_read: 0
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] read_ssh_id: reading
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] read 120
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] Ok("                        Running on a REAL Atari Mega 4 ST\r\n                      Glad to be back in the 21st Century!\r\n\r\n")
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] bytes_read: 0
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] read_ssh_id: reading
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] read 113
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] Ok("                    \"A lie is a very poor way to say hello.\"\r\n                                        -Edith Keel")
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] bytes_read: 0
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] read_ssh_id: reading
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] read 16
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] Ok("er\r\n\r\n          ")
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] bytes_read: 0
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] read_ssh_id: reading
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] read 130
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] Ok("                   STar Fleet Headquarters\r\n                             ~~~~~~~~~~~~~~~~~~~~~~~\r\n      Alias or Act# (or \"New\" fo")
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] bytes_read: 0
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] read_ssh_id: reading
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] read 13
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] Ok("r New User): ")
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] bytes_read: 0
[2024-12-20T15:26:42Z DEBUG russh::ssh_read] read_ssh_id: reading

And never returns.

@Eugeny
Copy link
Owner

Eugeny commented Dec 20, 2024

In the second case, you're connecting to a telnet server, not SSH.

@mkrueger
Copy link
Author

mkrueger commented Dec 21, 2024

Ah ok - but would be nice if the open_connection would cancel somehow in that case.

First case is the bbs from #418

20forbeers.com:1338

@Eugeny
Copy link
Owner

Eugeny commented Dec 21, 2024

The first one seems to work for me after the #418 fix

The SSH protocol allows for random data before the ID string at the beginning, so technically it's behaving correctly. Realistically, behaviour when connecting to a non compliant server is undefined.

@mkrueger
Copy link
Author

mkrueger commented Dec 21, 2024

Doesn't work for me - unfortunately. As a terminal I can't controlthe server - they're probably using some older openssh versions or custom ssh implementations.

Test case:

use std::{borrow::Cow, sync::Arc, time::Duration};

use async_trait::async_trait;
use russh::{cipher, client, kex, Preferred};
use russh_keys::ssh_key;

struct Client {}

#[async_trait]
impl client::Handler for Client {
    type Error = russh::Error;

    async fn check_server_key(
        &mut self,
        _server_public_key: &ssh_key::PublicKey,
    ) -> Result<bool, Self::Error> {
        Ok(true)
    }
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    simple_logger::init_with_level(log::Level::Debug).unwrap();

    let mut preferred = Preferred::DEFAULT.clone();
    preferred.kex = Cow::Owned(kex::ALL_KEX_ALGORITHMS.iter().map(|k| **k).collect());
    preferred.cipher = Cow::Owned(cipher::ALL_CIPHERS.iter().map(|k| **k).collect());
    let config = client::Config {
        inactivity_timeout: Some(Duration::from_secs(5)),
        preferred,
        ..<_>::default()
    };
    let config = Arc::new(config);
    let sh = Client {};
    println!("Connecting to SSH server");
    let _session = russh::client::connect(config, "20forbeers.com:1338", sh).await?;
    println!("Connected to SSH server");
    Ok(())
}

Deps:

[package]
name = "russh-test"
version = "0.1.0"
edition = "2024"

[dependencies]
anyhow = "1.0"
async-trait = "0.1.51"
tokio = "1.42.0"
log = "0.4.14"
simple_logger = "5.0.0"
russh = { git= "https://github.com/warp-tech/russh" }
russh-keys =  { git= "https://github.com/warp-tech/russh" }

Output:

Connecting to SSH server
2024-12-21T15:24:12.498Z DEBUG [russh::ssh_read] read_ssh_id: reading
2024-12-21T15:24:13.141Z DEBUG [russh::ssh_read] read 0
2024-12-21T15:24:13.141Z DEBUG [russh::ssh_read] Ok("")
Error: Disconnected

Note: doesn't change if I'm not using the altered Preferred struct.

@mkrueger
Copy link
Author

Ok seems to be the server side - I'll try to fix it with the sysop. TY

@mkrueger
Copy link
Author

It works - thank you - my users will love to get a new version :-). IcyTerm has some fans it's capable of simulating some old machines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants