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

Invalid port resolved for ProxyJump from ~/.ssh/config #351

Closed
pietrygamat opened this issue Mar 27, 2023 · 1 comment
Closed

Invalid port resolved for ProxyJump from ~/.ssh/config #351

pietrygamat opened this issue Mar 27, 2023 · 1 comment
Assignees
Labels
bug An issue describing a bug in the code
Milestone

Comments

@pietrygamat
Copy link

pietrygamat commented Mar 27, 2023

Version

2.9.2

Bug description

I have a ~/.ssh/config similar to this:

Host bastion
  Hostname 1.2.3.4
  User username
  IdentityFile ~/.ssh/id_rsa

Host server1
  ProxyJump bastion

Commandline ssh client works no problem for calls such as

ssh serverUser@server1
ssh bastion

and correctly assume port 22 is to be used.
However the sshClient does not assume default port for jumps, and results in exception:

try(SshClient sshClient = SshClient.setUpDefaultClient()) {
    sshClient.setHostConfigEntryResolver(new ConfigFileHostEntryResolver(sshConfigFile));
    sshClient.start();
    sshClient.connect("serverUser", "server1", 22);
} catch (Exception e) {
    throw new IllegalStateException(e);
}

Actual behavior

The jump entry is resolved as bastion: username@1.2.3.4:-1

Caused by: java.lang.IllegalArgumentException: Invalid port: -1
	at org.apache.sshd.common.util.ValidateUtils.createFormattedException(ValidateUtils.java:213) ~[sshd-common-2.9.2.jar:2.9.2]
	at org.apache.sshd.common.util.ValidateUtils.throwIllegalArgumentException(ValidateUtils.java:179) ~[sshd-common-2.9.2.jar:2.9.2]
	at org.apache.sshd.common.util.ValidateUtils.checkTrue(ValidateUtils.java:162) ~[sshd-common-2.9.2.jar:2.9.2]
	at org.apache.sshd.client.SshClient.doConnect(SshClient.java:556) ~[sshd-core-2.9.2.jar:2.9.2]
	at org.apache.sshd.client.SshClient.doConnect(SshClient.java:568) ~[sshd-core-2.9.2.jar:2.9.2]
	at org.apache.sshd.client.SshClient.connect(SshClient.java:546) ~[sshd-core-2.9.2.jar:2.9.2]
	at org.apache.sshd.client.SshClient.connect(SshClient.java:538) ~[sshd-core-2.9.2.jar:2.9.2]
	at org.apache.sshd.client.session.ClientSessionCreator.connect(ClientSessionCreator.java:74) ~[sshd-core-2.9.2.jar:2.9.2]
	at org.apache.sshd.client.session.ClientSessionCreator.connect(ClientSessionCreator.java:57) ~[sshd-core-2.9.2.jar:2.9.2]

Expected behavior

Perhaps org.apache.sshd.client.config.hosts.HostConfigEntry#resolvePort(int, int) when given two invalid arguments:
originalPort = -1 // from parsing URI
entryPort = 0 // from
should resolve to protocol default, and act the same way as commandline client would given the same set of data?

Relevant log output

No response

Other information

No response

@tomaswolf tomaswolf self-assigned this Apr 9, 2023
@tomaswolf tomaswolf added the bug An issue describing a bug in the code label Apr 9, 2023
@tomaswolf tomaswolf added this to the 2.10 milestone Apr 9, 2023
@tomaswolf
Copy link
Member

This was fixed by PR #353 done for issue #281.

tomaswolf added a commit that referenced this issue Apr 9, 2023

Unverified

The signing certificate or its chain could not be verified.
Just a somewhat redundant regression test to make sure GH-351 is fixed
by commit c11bfcc for GH-281.

Bug: #351
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue describing a bug in the code
Projects
None yet
Development

No branches or pull requests

2 participants