/// <summary> /// Creates a SHA256 string from the Client Hello Header /// </summary> /// <param name="ch"><see cref="ClientHelloHeader"/> the client hello header containing all information</param> /// <returns><see cref="SHA256"/> represented as a string</returns> public static String CreateSha(ClientHelloHeader ch) { String input = ch.ClientIP + ch.ClientUTCTime + ch.ClientVersion + ch.SizeInBytes; String now = DateTime.Now.ToString(); String nowUTC = DateTime.UtcNow.ToString(); input = now + input + nowUTC; input = new string(input.ToCharArray().OrderBy(x => Guid.NewGuid()).ToArray()); using (SHA256 hash = SHA256Managed.Create()) { return(string.Concat(hash .ComputeHash(Encoding.UTF8.GetBytes(input)) .Select(item => item.ToString("x2")))); } }
/// <summary> /// Gets the existing sha of the pending order /// </summary> /// <param name="chh"><see cref="ClientHelloHeader"/> containing all the information needed</param> /// <returns><see cref="SHA256"/> of pending order</returns> private static string GetExistingSha(ClientHelloHeader chh) { return(StorageProvider.GetInstance().GetSHAOfExistingOrder(chh.ClientIP)); }
/// <summary> /// Decides if the client can place a new order /// </summary> /// <param name="ch"><see cref="ClientHelloHeader"/> the client hello header containing all information</param> /// <returns>true if the client does not have any pending orders</returns> private static bool DecideAproval(ClientHelloHeader ch) { return(!StorageProvider.GetInstance().ClientHasOrder(ch.ClientIP)); }