From 83e2067751a5c8a45baf5b5123fa0a38992c1dfe Mon Sep 17 00:00:00 2001 From: Gert Driesen Date: Mon, 10 Mar 2014 13:48:32 +0000 Subject: [PATCH] Issue #1918: Connection dropped by server due to invalid DSA signature Pad each part of signature with zero's until its 20 bytes. Signature should be exactly 40 bytes. --- .../Security/Cryptography/DsaDigitalSignature.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Renci.SshClient/Renci.SshNet/Security/Cryptography/DsaDigitalSignature.cs b/Renci.SshClient/Renci.SshNet/Security/Cryptography/DsaDigitalSignature.cs index 0066763e..a9b47fc7 100644 --- a/Renci.SshClient/Renci.SshNet/Security/Cryptography/DsaDigitalSignature.cs +++ b/Renci.SshClient/Renci.SshNet/Security/Cryptography/DsaDigitalSignature.cs @@ -136,9 +136,19 @@ namespace Renci.SshNet.Security.Cryptography } while (s.IsZero); // The signature is (r, s) - return r.ToByteArray().Reverse().TrimLeadingZero().Concat(s.ToByteArray().Reverse().TrimLeadingZero()).ToArray(); + var signature = new byte[40]; + + // issue #1918: pad part with zero's on the left if length is less than 20 + var rBytes = r.ToByteArray().Reverse().TrimLeadingZero().ToArray(); + Array.Copy(rBytes, 0, signature, 20 - rBytes.Length, rBytes.Length); + + // issue #1918: pad part with zero's on the left if length is less than 20 + var sBytes = s.ToByteArray().Reverse().TrimLeadingZero().ToArray(); + Array.Copy(sBytes, 0, signature, 40 - sBytes.Length, sBytes.Length); + + return signature; } - + #region IDisposable Members private bool _isDisposed; @@ -192,6 +202,5 @@ namespace Renci.SshNet.Security.Cryptography } #endregion - } }