-
Notifications
You must be signed in to change notification settings - Fork 51
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
Set a maximum packet size of 32768 bytes for version and cleartext packets #49
base: main
Are you sure you want to change the base?
Conversation
…ckets - including those wrapping encrypted packets
Yes, I think so.
2^17 seems reasonable. |
@Lukasa how do you suggest passing the customisability down to the parser? |
Ideally the keys should know how to parse their own wire format, so that part isn’t too rough. The bigger issue is ensuring that we can dispatch to the right key type. We’ll likely need a place that users can register custom keys such that they can register their key identifiers. The bigger wrinkle is that some keys will trigger completely different user authentication flows. That needs some more consideration: we may need to allow users to plug in entirely separate user auth state machines, which is gonna be a bit of a tricky ask. |
@Lukasa I forgot about this branch, but just checked up on Swift-NIO-SSH in general and noticed them open. Can we merge this without customisability? And if not, how do we plan to tackle that? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should definitely add customisability, as well as tests that validate that we're appropriately enforcing this. I think the best way to add it is to add fields to the configuration objects.
Sources/NIOSSH/SSHPacketParser.swift
Outdated
// Prevent the consumed bytes for a version from exceeding the maximum packet size | ||
// In practice, if SSH version packets come anywhere near this it's already likely an attack | ||
// More data cannot be blindly regarded as malicious though, since these might be multiple packets | ||
let maximumVersionSize = min(slice.endIndex, self.maximumPacketSize) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ByteBufferView
is not necessarily zero-indexed, so self.maximumPacketSize
has to be translated into index-space first. I think this should be let maxIndex = slice.index(slice.startIndex, offsetBy: min(slice.count, self.maximumPacketSize))
.
@Lukasa while allowing users to configure the maximum packet size, shouldn't we still manually restrict the version size? |
Yup, I think so. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, this is looking really good! A few notes in the diff.
# Conflicts: # Tests/NIOSSHTests/EndToEndTests.swift
@Lukasa any idea what's failing? I can't see the build output |
|
I think the packet size should be a bit larger than the minimum requirement of 2^15 specified by SSH's RFC. I'd like to add some tests to this, and admittedly didn't test this at all. Before continuing I want to discuss a few questions first: