Пример #1
0
        public void PublicKeyImportWithPrivateKeyShouldFail()
        {
            bool isValid = SignatureVerifier.IsSignatureValid("this-is-not-important",
                                                              "absAUKYl78KAI3aA8FDWE2y2JATOCz7OUKG1hVhFNOyjSfwlGXhMA4oe3qou6JEnuKlsx+AqS5O+nz0oJ68FR7gLU8NPrWjVIWqFTyQMS0ntDRMEUl3oZXXD24fy+NaUOZ6o9OPxFASlEN/ueplXSgcedpXLfo0cfWQWM0GcTJ4=",
                                                              //next we will give public private exported csp
                                                              "BwIAAACkAABSU0EyAAQAAAEAAQBXZXt7QOileknWzBH2Sg+Yk4INDTbKA5XUUfUe23zUmr6eM1USCNHX3lidZfjk5Emuui1m8k0KnghxcJfOau8iPRpLg/lubMNojpLGe2MXn5GsyjgEpVdE+Cf0pLBAYHcBuBYHj99muMsJrJW1/InbKFa24JuVnBr+MybPuMXqtc9Ehyz/oomfsO6eYguHP4sqrvB595AFTtkKE7TcGmbt1dUWkSTxT0vfkvbVj0C/H8d7XlshIHlG1m2BEnFNi+T5CM2o0MH54c8DXKRhEujS+xeuk+u9POwL2/XLIvUcfMhL6Pt3o+Dk7HRkT3SPhRa/yJeZ1JEHpoVkYJOVfcXLfwijulTXJughtRpgd+0CBk4JSLYj0fkY+QyRWtuHQfAXTscNGGyW8uIMvHfPdNNOwuiKC4yZLfHuw+hQ1FDtTgH+iJ3nW5fwcIKudN0wusnRE3RIDo8QZky8AvAPb9Z/KbZHhpYXriWyfBKAfP9izhZaIcrRT6Fu+N9E+7oWkQY82jRwv237qtKOuqKl/WGcQE42vfBHWxmeKnBSzKZq8o+92oc06o2PYXqNqt38JOXn34W64nccPvINJJMIQ2UFoSydNf9D6iyxde86RDgSbNMxjqwEY3MiQmRs+QTG/8gwm5aiZG9Kr7K+3Vs65yr0NCwBmZ0DqMowmMbaeTrP3JYS/Ngr22p5vqtsYSTTGn/tU9mBL2asfWO4dxvkNXHCDNmendlCwvYKQZJONTS+GgxDfeC5i/lThMP1ua64H3I="
                                                              );

            Assert.True(!isValid);
        }
Пример #2
0
        public ActionResult PostInfluxTelemetry([FromBody] InfluxTelemetry telemetryPackage)
        {
            // verify in coming data
            if (telemetryPackage?.NodeId == null ||
                string.IsNullOrWhiteSpace(telemetryPackage.Signature) ||
                telemetryPackage.Payload == null ||
                telemetryPackage.Payload.Count == 0)
            {
                Console.WriteLine("bad request");
                return(BadRequest());
            }

            // Get Node key from keystore
            string nodeKey;

            try
            {
                nodeKey = _keyStore.GetKeyForNode(telemetryPackage.NodeId);
            }
            catch (KeyNotFoundException)
            {
                Console.WriteLine($"Node Unknown: {telemetryPackage.NodeId}");
                return(StatusCode(403));
            }

            // Verify Signature
            string signedPayload  = string.Join("", telemetryPackage.Payload);
            bool   signatureValid = SignatureVerifier.IsSignatureValid(signedPayload, telemetryPackage.Signature, nodeKey);

            if (!signatureValid)
            {
                Console.WriteLine($"Bad signature from node: {telemetryPackage.NodeId}");
                return(StatusCode(403));
            }

            Console.WriteLine($"Accepted telemetry from {telemetryPackage.NodeId} [{telemetryPackage.Payload.Count} metrics]");
            // Signature valid - record to db
            if (_influx.Enqueue(telemetryPackage.Payload, true))
            {
                return(Accepted());
            }
            else
            {
                return(StatusCode(400));
            }
        }
Пример #3
0
        public void SignatureShouldNotVerify(string pubKey, string payload, string signature)
        {
            bool isValid = SignatureVerifier.IsSignatureValid(payload, signature, pubKey);

            Assert.True(!isValid);
        }
Пример #4
0
        public ActionResult PostRealTimeTelemetry([FromBody] RealTimeTelemetry realTimePackage)
        {
            // verify incoming data
            if (realTimePackage?.NodeId == null ||
                string.IsNullOrWhiteSpace(realTimePackage.Signature) ||
                realTimePackage.Payload == null ||
                string.IsNullOrWhiteSpace(realTimePackage.Payload.Client) ||
                string.IsNullOrWhiteSpace(realTimePackage.Payload.BlockHash)
                )
            {
                Console.WriteLine("Bad Request: " + JsonConvert.SerializeObject(realTimePackage, Formatting.Indented));
                return(BadRequest());
            }

            // Get Node key from keystore
            string nodeKey;

            try
            {
                nodeKey = _keyStore.GetKeyForNode(realTimePackage.NodeId);
            }
            catch (KeyNotFoundException)
            {
                Console.WriteLine($"Node Unknown: {realTimePackage.NodeId}");
                return(StatusCode(403));
            }

            // Verify Signature
            string payload        = JsonConvert.SerializeObject(realTimePackage.Payload);
            bool   signatureValid = SignatureVerifier.IsSignatureValid(payload, realTimePackage.Signature, nodeKey);

            if (!signatureValid)
            {
                Console.WriteLine($"Bad signature from node: {realTimePackage.NodeId}");
                return(StatusCode(403));
            }


            //Point format |measurement|,tag_set| |field_set| |timestamp|

            //create a point from incoming JSON
            Console.WriteLine($"Accepted RT telemetry from {realTimePackage.NodeId} ");
            long   nanotimestamp = (long)(realTimePackage.Payload.BlockReceived * 1e9);
            string influxPoint   = string.Format("parity,nodeid={0},client={1} blocknum={2},numpeers={3},blockts={4},numtxinblock={5},propagationtime={6},gaslimit={8},gasused={9} {7}",
                                                 realTimePackage.NodeId,
                                                 realTimePackage.Payload.Client,
                                                 realTimePackage.Payload.BlockNum,
                                                 realTimePackage.Payload.NumPeers,
                                                 realTimePackage.Payload.BlockTS,
                                                 realTimePackage.Payload.NumTxInBlock,
                                                 (realTimePackage.Payload.BlockReceived - realTimePackage.Payload.BlockTS),
                                                 nanotimestamp,
                                                 realTimePackage.Payload.GasLimit,
                                                 realTimePackage.Payload.GasUsed);

            // Signature valid - record to db
            if (_influx.Enqueue(influxPoint, true))
            {
                return(Accepted());
            }
            else
            {
                return(StatusCode(400));
            }
        }