Skip to content

Commit 31b2019

Browse files
committed
Temporarily introduce extra verbose tracing.
1 parent 5260f1b commit 31b2019

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/Renci.SshNet/Security/KeyExchange.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,13 @@ public Cipher CreateServerCipher()
186186
var serverKey = Hash(GenerateSessionKey(SharedKey, ExchangeHash, 'D', sessionId));
187187

188188
serverKey = GenerateSessionKey(SharedKey, ExchangeHash, serverKey, _serverCipherInfo.KeySize / 8);
189-
189+
190+
DiagnosticAbstraction.Log(string.Format("[{0}] Creating server cipher (Name:{1},Key:{2},IV:{3})",
191+
Session.ToHex(Session.SessionId),
192+
Session.ConnectionInfo.CurrentServerEncryption,
193+
Session.ToHex(serverKey),
194+
Session.ToHex(serverVector)));
195+
190196
// Create server cipher
191197
return _serverCipherInfo.Cipher(serverKey, serverVector);
192198
}

src/Renci.SshNet/Session.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,9 +892,12 @@ private Message ReceiveMessage()
892892
// Read first block - which starts with the packet length
893893
var firstBlock = Read(blockSize);
894894

895+
DiagnosticAbstraction.Log(string.Format("[{0}] FirstBlock [{1}]: {2}", ToHex(SessionId), blockSize, ToHex(firstBlock)));
896+
895897
if (_serverCipher != null)
896898
{
897899
firstBlock = _serverCipher.Decrypt(firstBlock);
900+
DiagnosticAbstraction.Log(string.Format("[{0}] FirstBlock decrypted [{1}]: {2}", ToHex(SessionId), firstBlock.Length, ToHex(firstBlock)));
898901
}
899902

900903
var packetLength = (uint)(firstBlock[0] << 24 | firstBlock[1] << 16 | firstBlock[2] << 8 | firstBlock[3]);
@@ -924,25 +927,29 @@ private Message ReceiveMessage()
924927
{
925928
var nextBlocks = Read(bytesToRead);
926929

930+
DiagnosticAbstraction.Log(string.Format("[{0}] NextBlocks [{1}]: {2}", ToHex(SessionId), bytesToRead, ToHex(nextBlocks)));
931+
927932
if (serverHash != null)
928933
{
929934
Buffer.BlockCopy(nextBlocks, nextBlocks.Length - serverHash.Length, serverHash, 0, serverHash.Length);
930935
nextBlocks = nextBlocks.Take(nextBlocks.Length - serverHash.Length);
936+
937+
DiagnosticAbstraction.Log(string.Format("[{0}] ServerHash [{1}]: {2}", ToHex(SessionId), serverHash.Length, ToHex(serverHash)));
931938
}
932939

933940
if (nextBlocks.Length > 0)
934941
{
935942
if (_serverCipher != null)
936943
{
937944
nextBlocks = _serverCipher.Decrypt(nextBlocks);
945+
DiagnosticAbstraction.Log(string.Format("[{0}] NextBlocks decrypted [{1}]: {2}", ToHex(SessionId), nextBlocks.Length, ToHex(nextBlocks)));
938946
}
939947

940948
nextBlocks.CopyTo(data, blockSize + inboundPacketSequenceLength);
941949
}
942950
}
943951

944952
var paddingLength = data[inboundPacketSequenceLength + packetLengthFieldLength];
945-
946953
var messagePayloadLength = (int) (packetLength - paddingLength - paddingLengthFieldLength);
947954
var messagePayloadOffset = inboundPacketSequenceLength + packetLengthFieldLength + paddingLengthFieldLength;
948955

@@ -965,6 +972,8 @@ private Message ReceiveMessage()
965972
messagePayloadOffset = 0;
966973
}
967974

975+
DiagnosticAbstraction.Log(string.Format("[{0}] Message info (Sequence:{1},MessagePayloadLength:{2})", ToHex(SessionId), _inboundPacketSequence, messagePayloadLength));
976+
968977
_inboundPacketSequence++;
969978

970979
return LoadMessage(data, messagePayloadOffset);
@@ -1681,7 +1690,7 @@ private static string ToHex(byte[] bytes, int offset)
16811690
return builder.ToString();
16821691
}
16831692

1684-
private static string ToHex(byte[] bytes)
1693+
internal static string ToHex(byte[] bytes)
16851694
{
16861695
if (bytes == null)
16871696
return null;

0 commit comments

Comments
 (0)