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

Allow retrieving peer SSH Protocol Version String #260

Merged
merged 2 commits into from
Mar 14, 2024

Conversation

amtelekom
Copy link
Contributor

Allow retrieving peer SSH Protocol Version String

@@ -697,6 +697,7 @@ where
strict_kex: false,
alive_timeouts: 0,
received_data: false,
remote_sshid: String::from_utf8_lossy(sshid).into(),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering whether it is a good idea to use String as a type here. I guess there is nothing that says that the line has to be valid UTF-8. In practice I would assume the all non-broken implementations would only use ASCII which is a subset of UTF-8. The from_utf8_lossy would account for non-UTF-8, but a user of an API maybe does not want a lossy conversion to UTF-8, but what exactly came over the wire.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RFC4253 (SSH Transport) Section 4.2 defines

Both the 'protoversion' and 'softwareversion' strings MUST consist of
printable US-ASCII characters, with the exception of whitespace
characters and the minus sign (-).

So any valid SSH-ID is also valid UTF-8; of course the use of utf8_lossy would hide invalid implementations, but I don't think that's necessary here.
On the other hand, String makes it easier to continue working with the SSHID instead of pushing the task of conversion on the user - although I'd be open to changing it to a Vec<u8> if someone feels really strongly about this.

Copy link

@Rondom Rondom Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RFC4253 (SSH Transport) Section 4.2 defines

Both the 'protoversion' and 'softwareversion' strings MUST consist of
printable US-ASCII characters, with the exception of whitespace
characters and the minus sign (-).

I agree that it may be fine. I do not feel strongly about this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @Rondom - russh as a protocol library shouldn't make destructive decisions about data even if it's so rare and insignificant as invalid-UTF server ID - let's leave conversion up to the user

@amtelekom
Copy link
Contributor Author

I've changed it to return the raw &[u8]

@Eugeny Eugeny merged commit 0fcb1ec into warp-tech:main Mar 14, 2024
4 checks passed
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

Successfully merging this pull request may close these issues.

None yet

3 participants