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

SSH Host Key incorrectly used and checked on Windows #4003

Closed
Simba98 opened this issue Sep 14, 2023 · 5 comments
Closed

SSH Host Key incorrectly used and checked on Windows #4003

Simba98 opened this issue Sep 14, 2023 · 5 comments
Labels
bug Something isn't working network

Comments

@Simba98
Copy link

Simba98 commented Sep 14, 2023

Describe the bug
Start a server that has two SSHDs, with different ports, with different keys.

To Reproduce
Steps to reproduce the behavior:

  1. Server (Fedora 39 in VM) xpra start :XPRA_PORT
  2. Then try to connect SSH without ssh port (which means 22)
    &"C:\Program Files\Xpra\Xpra_cmd.exe" attach ssh://username@HOST/XPRA_PORT
    Xpra will write on (Windows Client) ~/.ssh/know_hosts without ssh port
    MY_DOMAIN_NAME ssh-ed25519 AAAAC3NzaC1SSH_Key_On_22_Port
  3. Then try to connect to another ssh port &"C:\Program Files\Xpra\Xpra_cmd.exe" attach ssh://username@HOST:SSH_PORT/XPRA_PORT
  4. Throws an SSH key changed error (should not because we did not connect to this port); and click yes, then xpra change the know_hosts
    It supposed to be [MY_DOMAIN_NAME]:SSH_PORT ssh-ed25519 AAAAC3NzaC1SSH_Key_On_Second_Port
  5. But Xpra overwrites the SSH_Key_On_22_Port to
    MY_DOMAIN_NAME ssh-ed25519 AAAAC3NzaC1SSH_Key_On_Second_Port
  6. This will prevent other ssh clients from connecting to 22 port if we use xpra to connect to some other ssh port.

System Information (please complete the following information):

  • Server OS: Fedora 39 in VM
  • Client OS: Windows 11
  • Xpra Server Version xpra v5.0.2-r0 on Fedora 39
  • Xpra Client Version xpra v5.0.2-r1 on Windows 11

Additional context
Temp Workaround: use host file to give xpra an individual domain to prevent xpra overwriting ssh key without port.

@Simba98 Simba98 added the bug Something isn't working label Sep 14, 2023
@Simba98 Simba98 changed the title SSH Key incorrectly used and checked on Windows SSH Host Key incorrectly used and checked on Windows Sep 14, 2023
@totaam
Copy link
Collaborator

totaam commented Sep 14, 2023

xpra start :XPRA_PORT

There is no XPRA_PORT, this is a display number.

This is not an xpra bug, the known hosts file is managed using the paramiko API:

host_keys.add(host, host_key.get_name(), host_key)

And this API doesn't have an argument for the port number:
https://docs.paramiko.org/en/latest/api/hostkeys.html#paramiko.hostkeys.HostKeys.add

You may want to switch to putty for this use-case.

@totaam totaam closed this as not planned Won't fix, can't repro, duplicate, stale Sep 14, 2023
@Simba98
Copy link
Author

Simba98 commented Sep 14, 2023

Hi Totamm,

You do not need the API provides port number as an argument, the [IP]:Port and [Host]:Port is hostname.

Hostnames is a comma-separated list of patterns (* and ? act as wildcards). Each pattern is matched against the canonical host name when authenticating a client or against the user-supplied name when authenticating a server. A pattern can also be preceded by ! to indicate negation. If the host name matches a negated pattern, it is not accepted by that line even if it matched another pattern on the line. A hostname or address can optionally be enclosed within '[' and ']' brackets, then followed by ':' and a nonstandard port number.
https://www.ibm.com/docs/en/zos/2.5.0?topic=daemon-ssh-known-hosts-file-format

And I have written a short test code for verifying paramiko support it.

from paramiko.hostkeys import HostKeys
host_keys = HostKeys()
# We use ./.ssh for prevent overwrite system .ssh folder
host_keys.load("./.ssh/known_hosts")

# Host 4 is starting with : host4,1.2.3.4 ecdsa-sha2-nistp256 AAAAE2VjZHNhLSomething
key4 = host_keys.lookup("host4")
key4ip = host_keys.lookup("1.2.3.4")
# You can get host4 via domain name and IP
key4["ecdsa-sha2-nistp256"]
key4ip["ecdsa-sha2-nistp256"]

# Host 5 is a normal one
key5 = host_keys.lookup("host5")

# Host 6 already have a section is [host6]:1023
key6 = host_keys.lookup("[host6]:1023")

# Now we add [host6]:1024
host_keys.add("[host6]:1024", 'ed25519', key5["ssh-ed25519"])

# Save it
host_keys.save("./.ssh/new_known_hosts")

Let me try if I can make a PR.

@totaam totaam reopened this Sep 14, 2023
@totaam
Copy link
Collaborator

totaam commented Oct 19, 2023

Bump.

@totaam totaam added the network label Oct 19, 2023
@totaam
Copy link
Collaborator

totaam commented Dec 3, 2023

Bump.

@totaam
Copy link
Collaborator

totaam commented Dec 25, 2023

Not heard back, closing.

@totaam totaam closed this as not planned Won't fix, can't repro, duplicate, stale Dec 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working network
Projects
None yet
Development

No branches or pull requests

2 participants