-
Notifications
You must be signed in to change notification settings - Fork 50
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
Updated Jim Studt's PR to support servers seeing user's usernames #125
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,11 +57,21 @@ struct SSHConnectionStateMachine { | |
case sentDisconnect(SSHConnectionRole) | ||
} | ||
|
||
class Attributes { | ||
var username: String? = nil | ||
} | ||
|
||
/// The state of this state machine. | ||
private var state: State | ||
|
||
/// Attributes of the connection which can be changed by messages handlers | ||
private let attributes: Attributes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As each of the states has a reference to the |
||
|
||
var username: String? { attributes.username } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure we need a computed property for this exactly here. |
||
|
||
init(role: SSHConnectionRole, protectionSchemes: [NIOSSHTransportProtection.Type] = Constants.bundledTransportProtectionSchemes) { | ||
self.state = .idle(IdleState(role: role, protectionSchemes: protectionSchemes)) | ||
self.attributes = Attributes() | ||
self.state = .idle(IdleState(role: role, protectionSchemes: protectionSchemes, attributes: attributes)) | ||
} | ||
|
||
func start() -> SSHMultiMessage? { | ||
|
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.
Is there any reason this isn't a
struct
?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.
Ah, I see: it's not a
struct
because we need some action at a distance to store the value.I don't love that. I wonder if we can refactor the code a bit. We have a few options.
The first option is that we could force the user auth delegate to tell us which username they're accepting. That's kind of tricky to do and a bit awkward.
The second option is that we could store a
class
only for the lifetime of the key exchange, and use that. Then reify this into a struct.The third option is that we could use a promise to resolve the username. I don't love that much, but it's do-able without being too painful.
The fourth option is to change the return value convention here somewhat so that we can also resolve a side-effect. Do you have any thoughts here?
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.
Hey Cory, thanks for the quick follow-up! I concur that it's sub-optimal. I merely updated the PR so you could leave your feedback, but will take it from here.
I don't think option 1 and 3 is a great API. It's going to be an awkward API to use for sure. One good option - in my eyes - is sending an event on the channel that indicates which user was authenticated. This leaves catching it to the implementations like Citadel.
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.
I'm open to sending an event on the channel.