Represents an instance of tox dns3.
Inheritance: IDisposable
Example #1
0
        private static string DiscoverToxId(string domain)
        {
            var services = new[]
            {
                new ToxNameService
                {
                    Domain = "toxme.se",
                    PublicKey = "5D72C517DF6AEC54F1E977A6B6F25914EA4CF7277A85027CD9F5196DF17E0B13"
                },
                new ToxNameService
                {
                    Domain = "utox.org",
                    PublicKey = "D3154F65D28A5B41A05D4AC7E4B39C6B1C233CC857FB365C56E8392737462A12"
                }
            };

            var service = FindNameService(domain.Split('@')[1]) ??
                          FindNameServiceFromStore(services, domain.Split('@')[1]);

            if (service == null)
            {
                //this name service does not use tox3, how unencrypted of them
                domain = domain.Replace("@", "._tox.");

                var records = GetSpfRecords(domain);
                if (records == null)
                    return null;

                foreach (var record in records)
                {
                    if (record.Contains("v=tox1"))
                    {
                        var entries = record.Split(';');

                        foreach (var entry in entries)
                        {
                            var parts = entry.Split('=');
                            var name = parts[0];
                            var value = parts[1];

                            if (name == "id")
                                return value;
                        }
                    }
                }
            }
            else
            {
                string publicKey;

                if (!string.IsNullOrWhiteSpace(service.PublicKey))
                    publicKey = service.PublicKey;
                else
                    return null;

                var split = domain.Split('@');

                var toxDns = new ToxDns(new ToxKey(ToxKeyType.Public, publicKey));
                uint requestId;
                var dns3String = toxDns.GenerateDns3String(split[0], out requestId);

                var query = string.Format("_{0}._tox.{1}", dns3String, split[1]);

                var records = GetSpfRecords(query);
                if (records == null)
                    return null;

                foreach (var record in records)
                {
                    if (record.Contains("v=tox3"))
                    {
                        var entries = record.Split(';');

                        foreach (var entry in entries)
                        {
                            var parts = entry.Split('=');
                            var name = parts[0];
                            var value = parts[1];

                            if (name == "id")
                            {
                                var result = toxDns.DecryptDns3TXT(value, requestId);

                                toxDns.Dispose();
                                return result;
                            }
                        }
                    }
                }

                toxDns.Dispose();
            }

            return null;
        }
Example #2
0
        public static string DiscoverToxID(string domain)
        {
            if (domain.Contains("@utox.org"))
            {
                string[] split = domain.Split('@');
                string public_key = new WebClient().DownloadString("http://utox.org/qkey");

                ToxDns tox_dns = new ToxDns(public_key);
                uint request_id;
                string dns3_string = tox_dns.GenerateDns3String(split[0], out request_id);

                string query = string.Format("_{0}._tox.{1}", dns3_string, split[1]);

                string[] records = GetSPFRecords(query);

                foreach (string record in records)
                {
                    if (record.Contains("v=tox3"))
                    {
                        string[] entries = record.Split(';');

                        foreach (string entry in entries)
                        {
                            string[] parts = entry.Split('=');
                            string name = parts[0];
                            string value = parts[1];

                            if (name == "id")
                            {
                                string result = tox_dns.DecryptDns3TXT(value, request_id);

                                tox_dns.Kill();
                                return result;
                            }
                        }
                    }
                }

                tox_dns.Kill();
            }
            else if (domain.Contains("@"))
            {
                domain = domain.Replace("@", "._tox.");

                string[] records = GetSPFRecords(domain);

                foreach (string record in records)
                {
                    if (record.Contains("v=tox1"))
                    {
                        string[] entries = record.Split(';');

                        foreach (string entry in entries)
                        {
                            string[] parts = entry.Split('=');
                            string name = parts[0];
                            string value = parts[1];

                            if (name == "id")
                                return value;
                        }
                    }
                }
            }

            return null;
        }
Example #3
0
        public static string DiscoverToxID(string domain, ToxNameService[] services, bool localStoreOnly)
        {
            ToxNameService service;

            if (!localStoreOnly)
                service = FindNameService(domain.Split('@')[1]) ?? FindNameServiceFromStore(services, domain.Split('@')[1]);
            else
                service = FindNameServiceFromStore(services, domain.Split('@')[1]);

            if (service == null)
            {
                //this name service does not use tox3, how unencrypted of them
                domain = domain.Replace("@", "._tox.");

                string[] records = GetSPFRecords(domain);

                foreach (string record in records)
                {
                    if (record.Contains("v=tox1"))
                    {
                        string[] entries = record.Split(';');

                        foreach (string entry in entries)
                        {
                            string[] parts = entry.Split('=');
                            string name = parts[0];
                            string value = parts[1];

                            if (name == "id")
                                return value;
                        }
                    }
                }
            }
            else
            {
                string public_key;

                if (!string.IsNullOrWhiteSpace(service.PublicKey))
                    public_key = service.PublicKey;
                else
                    return null;

                string[] split = domain.Split('@');

                ToxDns tox_dns = new ToxDns(new ToxKey(ToxKeyType.Public, public_key));
                uint request_id;
                string dns3_string = tox_dns.GenerateDns3String(split[0], out request_id);

                string query = string.Format("_{0}._tox.{1}", dns3_string, split[1]);

                string[] records = GetSPFRecords(query);

                foreach (string record in records)
                {
                    if (record.Contains("v=tox3"))
                    {
                        string[] entries = record.Split(';');

                        foreach (string entry in entries)
                        {
                            string[] parts = entry.Split('=');
                            string name = parts[0];
                            string value = parts[1];

                            if (name == "id")
                            {
                                string result = tox_dns.DecryptDns3TXT(value, request_id);

                                tox_dns.Dispose();
                                return result;
                            }
                        }
                    }
                }

                tox_dns.Dispose();
            }

            return null;
        }