Ejemplo n.º 1
0
        public DecriptKey GetDecryptKey(int db, string domain)
        {
            var privateKey = new DecriptKey();
            var dbUrl      = ComputeDBUrl(db, domain);
            var type       = ReadDNSTxtResult(dbUrl);

            privateKey.Storage = (KeyStorage)Enum.Parse(typeof(KeyStorage), type);
            switch (privateKey.Storage)
            {
            case KeyStorage.HTTP:
                var httpUrl = $"http.{dbUrl}";
                privateKey.Value = ReadDNSTxtResult(httpUrl);
                WebClient wc = new WebClient();
                privateKey.Key = wc.DownloadData(httpUrl);
                break;

            case KeyStorage.DNS:
                var baseUrl = $"pk.{dbUrl}";
                privateKey.Value = ReadDNSFragmentedText(baseUrl);
                privateKey.Key   = Convert.FromBase64String(privateKey.Value);
                break;

            default:
                //MANUAL DO NOTHING
                break;
            }

            return(privateKey);
        }
Ejemplo n.º 2
0
        public void CreateDatabase(int db, string domain, DecriptKey privateKey)
        {
            if (privateKey.Storage == KeyStorage.HTTP && !privateKey.Value.StartsWith("https", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new Exception("Only https address allowed");
            }

            var dbUrl   = ComputeDBUrl(db, domain);
            var dbItems = lookup.QueryAsync(dbUrl, QueryType.TXT).Result;

            if (dbItems == null || dbItems.Answers.Count == 0)
            {
                WriteDNSRecord(dbUrl, "TXT", privateKey.Storage.ToString());
            }
            switch (privateKey.Storage)
            {
            case KeyStorage.HTTP:
                var httpUrl = $"http.{dbUrl}";
                WriteDNSRecord(httpUrl, "TXT", privateKey.Value);
                break;

            case KeyStorage.DNS:
                var baseUrl = $"pk.{dbUrl}";
                WriteDNSFragmentedText(baseUrl, privateKey.Value, 254);
                break;

            default:
                //MANUAL DO NOTHING
                break;
            }
        }
Ejemplo n.º 3
0
        public void WriteDecryptKey()
        {
            var                domain        = "dns-blockchain.io";
            var                privateKey    = File.ReadAllBytes("./private.txt");
            LookupClient       lookupClient  = new LookupClient(IPAddress.Parse("127.0.0.1"), 53);
            ICryptoService     cryptoService = new CryptoService();
            IBlockChainService service       = new BlockChainService(cli, lookupClient, cryptoService);
            DecriptKey         decriptKey    = new DecriptKey();

            decriptKey.Storage = KeyStorage.DNS;
            decriptKey.Value   = Convert.ToBase64String(privateKey);
            service.CreateDatabase(1, domain, decriptKey);

            var key = service.GetDecryptKey(1, domain);

            Assert.Equal(key.Value, Convert.ToBase64String(privateKey));
            Assert.Equal(key.Key, privateKey);
        }