From 74bf6f3ba59308214362b1882ee4c2e7db26678c Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Wed, 4 May 2022 21:31:13 +0100 Subject: [PATCH] CP-36392: Fixes to sonarqube score. Signed-off-by: Konstantina Chremmou --- CommandLib/export.cs | 18 +++++++++++------- XenAdmin/VNC/VNCStream.cs | 15 +++++++++------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CommandLib/export.cs b/CommandLib/export.cs index 297d5b6a7..ca059aa2e 100644 --- a/CommandLib/export.cs +++ b/CommandLib/export.cs @@ -63,20 +63,24 @@ namespace CommandLib public class Export { + [System.Diagnostics.CodeAnalysis.SuppressMessage("csharpsquid", + "S4790:Using weak hashing algorithms is security-sensitive", + Justification = "Used only for checksum verification for backwards compatibility.")] + private readonly SHA1 _sha1 = new SHA1CryptoServiceProvider(); + + private readonly XXHash64 _xxHash = new XXHash64(); + public static bool verbose_debugging = false; - public static void debug(string x) + private static void debug(string x) { if (verbose_debugging) Console.WriteLine(x); } - private readonly SHA1 sha = new SHA1CryptoServiceProvider(); - private XXHash64 xxhash = new XXHash64(); - private string checksum_sha1(byte[] data) { - byte[] result = sha.ComputeHash(data); + byte[] result = _sha1.ComputeHash(data); return hex(result).ToLower(); } @@ -97,8 +101,8 @@ namespace CommandLib private string checksum_xxhash(byte[] data) { - xxhash.Initialize(); - return hex(xxhash.ComputeHash(data)); + _xxHash.Initialize(); + return hex(_xxHash.ComputeHash(data)); } private static Hashtable parse_checksum_table(string checksum_xml) diff --git a/XenAdmin/VNC/VNCStream.cs b/XenAdmin/VNC/VNCStream.cs index c2a905d85..b1d562d9d 100644 --- a/XenAdmin/VNC/VNCStream.cs +++ b/XenAdmin/VNC/VNCStream.cs @@ -150,6 +150,15 @@ namespace DotNetVnc public readonly object updateMonitor = new object(); + [System.Diagnostics.CodeAnalysis.SuppressMessage("csharpsquid", + "S5547:Cipher algorithms should be robust", + Justification = "Needed by the server side.")] + private DESCryptoServiceProvider des = new DESCryptoServiceProvider + { + Padding = PaddingMode.None, + Mode = CipherMode.ECB + }; + public VNCStream(IVNCGraphicsClient client, Stream stream, bool startPaused) { this.client = client; @@ -347,12 +356,6 @@ namespace DotNetVnc for (int i = 0; i < 8 && i < password.Length; ++i) keyBytes[i] = Reverse((byte)password[i]); - DESCryptoServiceProvider des = new DESCryptoServiceProvider - { - Padding = PaddingMode.None, - Mode = CipherMode.ECB - }; - ICryptoTransform cipher = des.CreateEncryptor(keyBytes, null); byte[] challenge = new byte[16];