// Fixture for #494: a legacy .NET Framework client with the weaknesses // DevSkim finds without a build. Not real code; never deployed. using System; using System.IO; using System.Net; using System.Security.Cryptography; using System.Xml; namespace Plant.Gateway { public class TelemetryClient { private static readonly Random Rng = new Random(); public TelemetryClient() { // Old protocol pinned for an old PLC gateway. ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3; // Every certificate accepted. ServicePointManager.ServerCertificateValidationCallback = (s, cert, chain, errors) => true; } public string NewSessionToken() { var bytes = new byte[16]; Rng.NextBytes(bytes); return Convert.ToBase64String(bytes); } public byte[] Encrypt(byte[] data, byte[] key) { using (var des = new DESCryptoServiceProvider()) { des.Key = key; return des.CreateEncryptor().TransformFinalBlock(data, 0, data.Length); } } public XmlDocument LoadConfig(Stream input) { var doc = new XmlDocument(); doc.XmlResolver = new XmlUrlResolver(); doc.Load(input); return doc; } } }