Skip to content

Return correct response for unknown messages, add handler for unknown messages to Session (extends #112) - #114

Open
jcspencer wants to merge 3 commits into
mainfrom
jspencer03/pr112-unknown-messages
Open

Return correct response for unknown messages, add handler for unknown messages to Session (extends #112)#114
jcspencer wants to merge 3 commits into
mainfrom
jspencer03/pr112-unknown-messages

Conversation

@jcspencer

Copy link
Copy Markdown
Collaborator

This PR builds on the changes proposed by @cquintana92 in #112 (fix: unknown request types should return failure)

This:

  • Extends Request::Unknown to include an payload of type Unparsed.
  • Add Session::unknown_message() method to Session trait to allow processing messages not known to the library
  • Adds a roundtrip test case for an unknown message.

See #112 for more information on the original issue.

cquintana92 and others added 2 commits August 12, 2026 16:12
Signed-off-by: Carlos Quintana <carlos@cquintana.dev>
Signed-off-by: James Spencer <github@jcspencer.net>
Comment thread src/agent.rs

/// Handle the case where an unknown message is received from the client.
///
/// By default - per [RFC9987 § 5.1](https://www.rfc-editor.org/rfc/rfc9987.html#section-5.1) -

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Note to self: we should probably update the references to the draft RFC now that it's been accepted as a proposed standard 🤔

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Good idea, I think we can create an issue and then tackle that separately 👌

Comment thread src/agent.rs
/// However, if the message type _is_ known, a custom response can be returned to the client.
async fn unknown_message(
&mut self,
message_id: u8,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We interchage message_id and command in a few places; the RFC refers to them as type. Happy to take suggestions!

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Having one unified name that is aligned with the RFC would be ideal. Sadly type is a keyword in Rust 😥 we need something else hmm... type_id? 🤔 I'm not sure...

The timing to adjust all these places is good though since this would change the API anyway 😅


/// From [PR#112](https://github.com/wiktor-k/ssh-agent-lib/pull/112), this
/// payload is an:
/// > `SSH2_AGENT_REQUEST_VERSION` (message type 1) [request] with a "2.0" payload,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Note that although the new Session::unknown_message handler allows responding to messages, it doesn't support custom response messages (yet). Perhaps we could add a Response variant to handle that in a follow-up PR 🤔

Add `Session::unknown_message` variant to allow processing messages not known to the library

Add roundtrip test case for `Unknown` request type

Remove `tests/unknown_request.rs` test now that the message is being roundtripped.

Signed-off-by: James Spencer <github@jcspencer.net>
@jcspencer
jcspencer force-pushed the jspencer03/pr112-unknown-messages branch from c411825 to a09599d Compare September 5, 2026 06:56

@wiktor-k wiktor-k left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Looks great IMO. We need a rebase on top of main for the CI to be green again 🍃

Comment thread src/agent.rs

/// Handle the case where an unknown message is received from the client.
///
/// By default - per [RFC9987 § 5.1](https://www.rfc-editor.org/rfc/rfc9987.html#section-5.1) -

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Good idea, I think we can create an issue and then tackle that separately 👌

Comment thread src/agent.rs
/// However, if the message type _is_ known, a custom response can be returned to the client.
async fn unknown_message(
&mut self,
message_id: u8,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Having one unified name that is aligned with the RFC would be ideal. Sadly type is a keyword in Rust 😥 we need something else hmm... type_id? 🤔 I'm not sure...

The timing to adjust all these places is good though since this would change the API anyway 😅

Comment thread src/agent.rs
Comment on lines +313 to +316
return match self.unknown_message(message_id, payload).await? {
Some(response) => Ok(response),
None => Ok(Response::Failure),
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This is totally my preference but for Options I like using if let instead:

Suggested change
return match self.unknown_message(message_id, payload).await? {
Some(response) => Ok(response),
None => Ok(Response::Failure),
}
return if let Some(response) self.unknown_message(message_id, payload).await? {
Ok(response)
} else {
Ok(Response::Failure),
}

(with the formatting adjusted 😅 )

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.

3 participants