Exemplo n.º 1
0
        private static void threadProcNodeC(object testData_)
        {
            var testData = (TestData)testData_;
            var _log     = NLog.LogManager.GetLogger("NodeCThread");

            _log.Info("Creating node C...");

            var nodeC = new Nemesis.NemesisNode(testData.NodeCId, testData.Ports, "localhost", false);

            nodeC.SetLogName("nNodeC");
            nodeC.PermitPublicKeyUpload = true;

            nodeC.CommandReceived += NodeC_CommandReceived;

            nodeC.Connect();


            var cmdTest = "n2h";

            _log.Info($"Sending command \"{cmdTest}\" (1/2) from Node C to Hub");

            var response = nodeC.SendCommand(cmdTest);

            _log.Info("Got response: {0}", response.Result);



            _log.Info($"Sending command \"{cmdTest}\" (2/2) from Node C to Hub");
            response = nodeC.SendCommand(cmdTest);
            _log.Info("Got response: {0}", response.Result);
        }
Exemplo n.º 2
0
        private static void threadProcNodeC(object testData_)
        {
            var testData = (TestData)testData_;
            var _log = NLog.LogManager.GetLogger("NodeCThread");

            _log.Info("Creating node C...");

            var nodeC = new Nemesis.NemesisNode(testData.NodeCId, testData.Ports, "localhost", false);

            nodeC.SetLogName("nNodeC");
            nodeC.PermitPublicKeyUpload = true;

            nodeC.CommandReceived += NodeC_CommandReceived;

            nodeC.Connect();


            var cmdTest = "n2h";
            _log.Info($"Sending command \"{cmdTest}\" (1/2) from Node C to Hub");

            var response = nodeC.SendCommand(cmdTest);
            _log.Info("Got response: {0}", response.Result);



            _log.Info($"Sending command \"{cmdTest}\" (2/2) from Node C to Hub");
            response = nodeC.SendCommand(cmdTest);
            _log.Info("Got response: {0}", response.Result);



        }
Exemplo n.º 3
0
        private static void threadProcNodeB(object testData_)
        {
            var testData = (TestData)testData_;
            var _log = NLog.LogManager.GetLogger("NodeBThread");

            _log.Info("Creating node B...");

            var ke = new RSA();

            var badKeyStore = new MemoryKeyStore(ke);
            badKeyStore.Load(testData.NodeAKeys); // Note: The WRONG keystore

            var nodeBKeyStore = new MemoryKeyStore(ke);
            nodeBKeyStore.Load(testData.NodeAKeys);

            var nodeB = new Nemesis.NemesisNode(testData.NodeBId, testData.Ports, testData.Host.ToString(), false);
            nodeB.SetLogName("nNodeB");

            nodeB.CommandReceived += NodeB_CommandReceived;

            //var hubKeyStore = new MemoryKeyStore();
            //hubKeyStore.Load(testData.HubKeys);
            //nodeB.HubPublicKey = hubKeyStore.PublicKey;
            nodeB.HubPublicKey = badKeyStore.PublicKey; // Note: Again; the wrong key

            nodeB.EnableEncryption(badKeyStore);

            nodeB.Connect();

            var cmdTest = "n2h";
            _log.Info($"Sending command \"{cmdTest}\" with WRONG ENCODING from Node B to Hub");

            try {
                var response = nodeB.SendCommand(cmdTest);
                var r = response.Result; // Note: Will fail
            }
            catch (Exception x)
            {
                _log.Warn("Oh no! " + x.Message);
            }

            nodeB.EnableEncryption(nodeBKeyStore);

            _log.Info($"Sending command \"{cmdTest}\" with the RIGHT ENCODING from Node B to Hub");

            try {
                var response = nodeB.SendCommand(cmdTest);
                _log.Info("Got result: " + response.Result); // Note: Will fail
            }
            catch (Exception x)
            {
                _log.Warn("Oh no! " + x.Message);
            }

            //var hubKeyStore = new MemoryKeyStore();
            //hubKeyStore.Load(testData.HubKeys);
            //nodeB.HubPublicKey = hubKeyStore.PublicKey;

        }
Exemplo n.º 4
0
        private static void threadProcNodeA(object testData_)
        {
            var testData = (TestData)testData_;
            var _log     = NLog.LogManager.GetLogger("NodeAThread");

            _log.Info("Creating node A...");

            var keyStore = new MemoryKeyStore(RSA.Default);

            keyStore.Load(testData.NodeAKeys);


            var nodeA = new Nemesis.NemesisNode(testData.NodeAId, testData.Ports, testData.Host.ToString(), false);

            nodeA.SetLogName("nNodeA");

            nodeA.CommandReceived += NodeA_CommandReceived;

            var hubKeyStore = new MemoryKeyStore(RSA.Default);

            hubKeyStore.Load(testData.HubKeys);
            nodeA.HubPublicKey = hubKeyStore.PublicKey;

            nodeA.EnableEncryption(keyStore);

            nodeA.Connect();


            var cmdTest = "n2h";

            _log.Info($"Sending command \"{cmdTest}\" (1/2) from Node A to Hub");

            var response = nodeA.SendCommand(cmdTest);

            _log.Info("Got response: {0}", response.Result);



            _log.Info($"Sending command \"{cmdTest}\" (2/2) from Node A to Hub");
            response = nodeA.SendCommand(cmdTest);
            _log.Info("Got response: {0}", response.Result);
        }
Exemplo n.º 5
0
        private static void threadProcNodeA(object testData_)
        {
            var testData = (TestData)testData_;
            var _log = NLog.LogManager.GetLogger("NodeAThread");

            _log.Info("Creating node A...");

            var keyStore = new MemoryKeyStore(RSA.Default);
            keyStore.Load(testData.NodeAKeys);


            var nodeA = new Nemesis.NemesisNode(testData.NodeAId, testData.Ports, testData.Host.ToString(), false);

            nodeA.SetLogName("nNodeA");

            nodeA.CommandReceived += NodeA_CommandReceived;
            
            var hubKeyStore = new MemoryKeyStore(RSA.Default);
            hubKeyStore.Load(testData.HubKeys);
            nodeA.HubPublicKey = hubKeyStore.PublicKey;

            nodeA.EnableEncryption(keyStore);

            nodeA.Connect();

   
            var cmdTest = "n2h";
            _log.Info($"Sending command \"{cmdTest}\" (1/2) from Node A to Hub");

            var response = nodeA.SendCommand(cmdTest);
            _log.Info("Got response: {0}", response.Result);
            


            _log.Info($"Sending command \"{cmdTest}\" (2/2) from Node A to Hub");
            response = nodeA.SendCommand(cmdTest);
            _log.Info("Got response: {0}", response.Result);



        }
Exemplo n.º 6
0
        private static void threadProcNodeB(object testData_)
        {
            var testData = (TestData)testData_;
            var _log     = NLog.LogManager.GetLogger("NodeBThread");

            _log.Info("Creating node B...");

            var ke = new RSA();

            var badKeyStore = new MemoryKeyStore(ke);

            badKeyStore.Load(testData.NodeAKeys); // Note: The WRONG keystore

            var nodeBKeyStore = new MemoryKeyStore(ke);

            nodeBKeyStore.Load(testData.NodeAKeys);

            var nodeB = new Nemesis.NemesisNode(testData.NodeBId, testData.Ports, testData.Host.ToString(), false);

            nodeB.SetLogName("nNodeB");

            nodeB.CommandReceived += NodeB_CommandReceived;

            //var hubKeyStore = new MemoryKeyStore();
            //hubKeyStore.Load(testData.HubKeys);
            //nodeB.HubPublicKey = hubKeyStore.PublicKey;
            nodeB.HubPublicKey = badKeyStore.PublicKey; // Note: Again; the wrong key

            nodeB.EnableEncryption(badKeyStore);

            nodeB.Connect();

            var cmdTest = "n2h";

            _log.Info($"Sending command \"{cmdTest}\" with WRONG ENCODING from Node B to Hub");

            try {
                var response = nodeB.SendCommand(cmdTest);
                var r        = response.Result; // Note: Will fail
            }
            catch (Exception x)
            {
                _log.Warn("Oh no! " + x.Message);
            }

            nodeB.EnableEncryption(nodeBKeyStore);

            _log.Info($"Sending command \"{cmdTest}\" with the RIGHT ENCODING from Node B to Hub");

            try {
                var response = nodeB.SendCommand(cmdTest);
                _log.Info("Got result: " + response.Result); // Note: Will fail
            }
            catch (Exception x)
            {
                _log.Warn("Oh no! " + x.Message);
            }

            //var hubKeyStore = new MemoryKeyStore();
            //hubKeyStore.Load(testData.HubKeys);
            //nodeB.HubPublicKey = hubKeyStore.PublicKey;
        }