From 31b2019fe4a4aaa17ed45013d770f7bf68ff0cf9 Mon Sep 17 00:00:00 2001 From: drieseng Date: Tue, 23 Aug 2016 18:25:52 +0200 Subject: [PATCH] Temporarily introduce extra verbose tracing. --- src/Renci.SshNet/Security/KeyExchange.cs | 8 +++++++- src/Renci.SshNet/Session.cs | 13 +++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Renci.SshNet/Security/KeyExchange.cs b/src/Renci.SshNet/Security/KeyExchange.cs index 9eb29fad..75e3517a 100644 --- a/src/Renci.SshNet/Security/KeyExchange.cs +++ b/src/Renci.SshNet/Security/KeyExchange.cs @@ -186,7 +186,13 @@ namespace Renci.SshNet.Security var serverKey = Hash(GenerateSessionKey(SharedKey, ExchangeHash, 'D', sessionId)); serverKey = GenerateSessionKey(SharedKey, ExchangeHash, serverKey, _serverCipherInfo.KeySize / 8); - + + DiagnosticAbstraction.Log(string.Format("[{0}] Creating server cipher (Name:{1},Key:{2},IV:{3})", + Session.ToHex(Session.SessionId), + Session.ConnectionInfo.CurrentServerEncryption, + Session.ToHex(serverKey), + Session.ToHex(serverVector))); + // Create server cipher return _serverCipherInfo.Cipher(serverKey, serverVector); } diff --git a/src/Renci.SshNet/Session.cs b/src/Renci.SshNet/Session.cs index 2afa46a0..44296f0d 100644 --- a/src/Renci.SshNet/Session.cs +++ b/src/Renci.SshNet/Session.cs @@ -892,9 +892,12 @@ namespace Renci.SshNet // Read first block - which starts with the packet length var firstBlock = Read(blockSize); + DiagnosticAbstraction.Log(string.Format("[{0}] FirstBlock [{1}]: {2}", ToHex(SessionId), blockSize, ToHex(firstBlock))); + if (_serverCipher != null) { firstBlock = _serverCipher.Decrypt(firstBlock); + DiagnosticAbstraction.Log(string.Format("[{0}] FirstBlock decrypted [{1}]: {2}", ToHex(SessionId), firstBlock.Length, ToHex(firstBlock))); } var packetLength = (uint)(firstBlock[0] << 24 | firstBlock[1] << 16 | firstBlock[2] << 8 | firstBlock[3]); @@ -924,10 +927,14 @@ namespace Renci.SshNet { var nextBlocks = Read(bytesToRead); + DiagnosticAbstraction.Log(string.Format("[{0}] NextBlocks [{1}]: {2}", ToHex(SessionId), bytesToRead, ToHex(nextBlocks))); + if (serverHash != null) { Buffer.BlockCopy(nextBlocks, nextBlocks.Length - serverHash.Length, serverHash, 0, serverHash.Length); nextBlocks = nextBlocks.Take(nextBlocks.Length - serverHash.Length); + + DiagnosticAbstraction.Log(string.Format("[{0}] ServerHash [{1}]: {2}", ToHex(SessionId), serverHash.Length, ToHex(serverHash))); } if (nextBlocks.Length > 0) @@ -935,6 +942,7 @@ namespace Renci.SshNet if (_serverCipher != null) { nextBlocks = _serverCipher.Decrypt(nextBlocks); + DiagnosticAbstraction.Log(string.Format("[{0}] NextBlocks decrypted [{1}]: {2}", ToHex(SessionId), nextBlocks.Length, ToHex(nextBlocks))); } nextBlocks.CopyTo(data, blockSize + inboundPacketSequenceLength); @@ -942,7 +950,6 @@ namespace Renci.SshNet } var paddingLength = data[inboundPacketSequenceLength + packetLengthFieldLength]; - var messagePayloadLength = (int) (packetLength - paddingLength - paddingLengthFieldLength); var messagePayloadOffset = inboundPacketSequenceLength + packetLengthFieldLength + paddingLengthFieldLength; @@ -965,6 +972,8 @@ namespace Renci.SshNet messagePayloadOffset = 0; } + DiagnosticAbstraction.Log(string.Format("[{0}] Message info (Sequence:{1},MessagePayloadLength:{2})", ToHex(SessionId), _inboundPacketSequence, messagePayloadLength)); + _inboundPacketSequence++; return LoadMessage(data, messagePayloadOffset); @@ -1681,7 +1690,7 @@ namespace Renci.SshNet return builder.ToString(); } - private static string ToHex(byte[] bytes) + internal static string ToHex(byte[] bytes) { if (bytes == null) return null;