private static async void HandleGoodwitchConnection(object obj) { var Goodwitch = (TcpClient)obj; NetworkStream NStream = null; await Task.Run(() => ConnectedGoodwitchQueue.Add(Goodwitch)); await Task.Run(() => Logger.Log($"Goodwitch instance connected: {((IPEndPoint)Goodwitch.Client.RemoteEndPoint).Address.ToString()} | (Goodwitch#: {ConnectedGoodwitchQueue.IndexOf(Goodwitch) + 1} of {ConnectedGoodwitchQueue.Count})")); await Task.Run(() => NStream = Goodwitch.GetStream()); await Task.Run(() => { var RecievedPacket = ServerTelemetry.ReadPacket(NStream); var CurrentGoodwitchInstanceNum = ConnectedGoodwitchQueue.IndexOf(Goodwitch) + 1; if (RecievedPacket.Item1) { var UniqueGoodwitchFingerprint = RecievedPacket.Item2.Replace("CheckGoodwitchFingerprint: ", "").Replace(GLOBAL_KEY, ""); Logger.Log($"Goodwitch instance#: {CurrentGoodwitchInstanceNum} has requested for fingerprint check."); if (RecievedPacket.Item2.Contains("c60b189c3ac4722971ddfb00a12524c9")) { Logger.Log($"Valid global key for Goodwitch instance#: {CurrentGoodwitchInstanceNum}\n(Goodwitch fingerprint: {UniqueGoodwitchFingerprint})", Logger.LogSeverity.Information); FingerprintAuthService.AuthenticateFingerprint(NStream, RecievedPacket.Item2); } else { Logger.Log($"Invalid global key for Goodwitch instance#: {CurrentGoodwitchInstanceNum}\n(GoodwitchFingerprint: {UniqueGoodwitchFingerprint})", Logger.LogSeverity.Warning); ServerTelemetry.SendPacket(NStream, $"InvalidGlobalKey"); } } else { Logger.Log($"Exception occured for Goodwitch instance#: {CurrentGoodwitchInstanceNum} while reading the sent packet: {RecievedPacket.Item2}.", Logger.LogSeverity.Danger); ServerTelemetry.SendPacket(NStream, $"Exception ocurred while reading the sent packet: {RecievedPacket.Item2}"); } }); }
internal static void AuthenticateFingerprint(NetworkStream NStream, string Fingerprint) { string trueFingerPrint = Fingerprint.Replace("CheckGoodwitchFingerprint: ", ""); string uniqueFingerPrint = trueFingerPrint.Replace("63ebcba8d37ddf1551d9a500133b4e91", ""); Fingerprint = trueFingerPrint + uniqueFingerPrint; var fpDB = OpenFingerprintDatabase(); if (fpDB["Fingerprints"].Contains(new Dictionary <string, object>() { { Fingerprint, "" } })) { ServerTelemetry.SendPacket(NStream, "ValidGoodwitchFingerprint"); Service.HandleIncomingReports(NStream); } else { RegisterFingerprint(fpDB, Fingerprint); ServerTelemetry.SendPacket(NStream, "GoodwitchFingerprintRegistered"); Service.HandleIncomingReports(NStream); } }