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

Updated Jim Studt's PR to support servers seeing user's usernames #125

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Joannis
Copy link
Collaborator

@Joannis Joannis commented Nov 19, 2022

Fixes #57 and obsoletes #58

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@@ -57,11 +57,21 @@ struct SSHConnectionStateMachine {
case sentDisconnect(SSHConnectionRole)
}

class Attributes {
Copy link
Collaborator

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?

Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

/// 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
Copy link
Collaborator

Choose a reason for hiding this comment

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

As each of the states has a reference to the attributes, I think I'd recommend making this computed and switching over the states to get hold of the value.

/// Attributes of the connection which can be changed by messages handlers
private let attributes: Attributes

var username: String? { attributes.username }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure we need a computed property for this exactly here.

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.

Is the SSH user name accessible by the ChannelHandler?
3 participants