Skip to content

Commit

Permalink
Tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmds committed Aug 28, 2024
1 parent ac46f41 commit 8e08dc3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Tmds.Ssh/ECDHKeyExchange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public async Task<KeyExchangeOutput> TryExchangeAsync(KeyExchangeContext context
await context.SendPacketAsync(CreateEcdhInitMessage(sequencePool, q_c), ct).ConfigureAwait(false);

// Receive ECDH_REPLY.
using Packet exchangeInitMsg = await context.ReceivePacketAsync(MessageId.SSH_MSG_KEX_ECDH_REPLY, firstPacket.Move(), ct).ConfigureAwait(false);
var ecdhReply = ParceEcdhReply(exchangeInitMsg);
using Packet ecdhReplyMsg = await context.ReceivePacketAsync(MessageId.SSH_MSG_KEX_ECDH_REPLY, firstPacket.Move(), ct).ConfigureAwait(false);
var ecdhReply = ParceEcdhReply(ecdhReplyMsg);

// Verify received key is valid.
connectionInfo.ServerKey = ecdhReply.public_host_key;
Expand Down
11 changes: 9 additions & 2 deletions src/Tmds.Ssh/KeyExchangeContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ public KeyExchangeContext(SshConnection connection, SshSession session, bool isI

public SequencePool SequencePool => _connection.SequencePool;

public ValueTask<Packet> ReceivePacketAsync(CancellationToken ct)
=> _connection.ReceivePacketAsync(ct);
public async ValueTask<Packet> ReceivePacketAsync(CancellationToken ct)
{
var packet = await _connection.ReceivePacketAsync(ct).ConfigureAwait(false);
if (packet.IsEmpty)
{
ThrowHelper.ThrowProtocolUnexpectedPeerClose();
}
return packet;
}

public async ValueTask<Packet> ReceivePacketAsync(MessageId expected, CancellationToken ct)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Tmds.Ssh/SshSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ private async Task ReceiveLoopAsync(SshConnection connection, SshConnectionInfo
// The send loop waits for us to signal kex completion.
try
{
await PerformKeyExchangeAsync(context, packet, clientKexInitMsg, abortToken).ConfigureAwait(false);
await PerformKeyExchangeAsync(context, serverKexInitMsg: packet, clientKexInitMsg, abortToken).ConfigureAwait(false);
}
finally
{
Expand All @@ -419,7 +419,7 @@ private async Task ReceiveLoopAsync(SshConnection connection, SshConnectionInfo

internal void HandleNonKexPacket(MessageId msgId, Packet _p)
{
using Packet packet = _p; // own the dispose.
using Packet packet = _p; // Ensure dispose

// Connection Protocol: https://tools.ietf.org/html/rfc4254.
switch (msgId)
Expand Down

0 comments on commit 8e08dc3

Please sign in to comment.