Ejemplo n.º 1
0
        public void Initialize(NodeId masterNodeKey = null)
        {
            Buckets = new NodeBucket[_configurationProvider.BucketsCount];
            var pass    = new SecureString();
            var rawPass = _configurationProvider.KeyPass;

            for (var i = 0; i < rawPass.Length; i++)
            {
                pass.AppendChar(rawPass[i]);
            }
            pass.MakeReadOnly();

            if (masterNodeKey == null)
            {
                var key = _keyStore.GenerateKey(pass);
                if (key.Item2.ResultType == ResultType.Failure)
                {
                    var msg = $"Cannot create key, error: {key.Item2.Error}";
                    _logger.Error(msg);
                    throw new Exception(msg);
                }

                masterNodeKey = new NodeId(key.PrivateKey.PublicKey);
            }

            MasterNode = _nodeFactory.CreateNode(masterNodeKey, _configurationProvider.MasterHost, _configurationProvider.MasterPort);
            _logger.Info($"Created MasterNode: {MasterNode}");

            for (var i = 0; i < Buckets.Length; i++)
            {
                Buckets[i] = new NodeBucket(i, _configurationProvider.BucketSize);
            }
        }
Ejemplo n.º 2
0
        public void CryptoVersionMismatchTest()
        {
            //generate key
            (PrivateKey, Result)key = _store.GenerateKey(_testPasswordSecured);
            Assert.AreEqual(ResultType.Success, key.Item2.ResultType);

            //replace version
            string       filePath = Path.Combine(_configurationProvider.GetConfig <KeystoreConfig>().KeyStoreDirectory, key.Item1.Address.ToString());
            KeyStoreItem item     = _serializer.Deserialize <KeyStoreItem>(File.ReadAllText(filePath));

            item.Crypto.Version = 0;
            string json = _serializer.Serialize(item);

            File.WriteAllText(filePath, json);

            //try to read
            (PrivateKey, Result)key2 = _store.GetKey(key.Item1.Address, _testPasswordSecured);
            Assert.AreEqual(ResultType.Failure, key2.Item2.ResultType);
            Assert.AreEqual("Crypto version mismatch", key2.Item2.Error);

            //clean up
            File.Delete(filePath);
        }
 public Address NewAccount(SecureString passphrase)
 {
     (PrivateKey privateKey, _) = _keyStore.GenerateKey(passphrase);
     return(privateKey.Address);
 }