microsoft / dev-tunnels-ssh

SSH library for dev-tunnels
MIT License
130 stars 17 forks source link

Missing Public API for SSH Extensions #97

Open Bip901 opened 5 months ago

Bip901 commented 5 months ago

Currently, the only public API to obtain the protocol extensions is the following property of SshSession:

// Summary:
//     Gets the set of protocol extensions (and their values) enabled for the current
//     session.
//
// Remarks:
//     Populated only after an (optional) ExtensionInfoMessage is received from the
//     other side.
public IReadOnlyDictionary<string, string>? ProtocolExtensions => Protocol?.Extensions;

Which is implemented by taking the intersection of the local and remote extensions:

// file SshSession.cs, method HandleMessageAsync(ExtensionInfoMessage message, CancellationToken cancellation)

foreach (string protocolExtension in Config.ProtocolExtensions)
{
    if (extensionInfo.TryGetValue(protocolExtension, out var value))
    {
        Protocol.Extensions.Add(protocolExtension, value);
    }
}

This results in loss of information, as there's no other public API to obtain the extensions the remote party advertised and aren't in the local extension list.

Some SSH extensions are only advertised by one of the parties, as noted by RFC 8308:

   When it is specified, an extension MAY dictate that, in order to take
   effect, both parties must include it in their SSH_MSG_EXT_INFO or
   that it is sufficient for only one party to include it.