Example #1
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp      = (IPAddress)ArgumentValues["Node IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

            log.Trace("(NodeIp:'{0}',PrimaryPort:{1})", NodeIp, PrimaryPort);

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

                // Step 1
                await client.ConnectAsync(NodeIp, PrimaryPort, false);

                Message requestMessage = client.CreateStartConversationRequest();
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

                bool idOk                = responseMessage.Id == requestMessage.Id;
                bool statusOk            = responseMessage.Response.Status == Status.Ok;
                bool verifyChallengeOk   = client.VerifyNodeChallengeSignature(responseMessage);
                bool startConversationOk = idOk && statusOk && verifyChallengeOk;

                byte[] challenge = responseMessage.Response.ConversationResponse.Start.Challenge.ToByteArray();

                requestMessage = mb.CreateCheckInRequest(challenge);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.ErrorBadRole;
                bool checkInOk = idOk && statusOk;

                // Step 1 Acceptance

                Passed = startConversationOk && checkInOk;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            client.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
Example #2
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp            = (IPAddress)ArgumentValues["Node IP"];
            int       ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];

            log.Trace("(NodeIp:'{0}',ClNonCustomerPort:{1})", NodeIp, ClNonCustomerPort);

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

                // Step 1
                await client.ConnectAsync(NodeIp, ClNonCustomerPort, true);

                Message requestMessage = client.CreateStartConversationRequest();
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

                // Step 1 Acceptance
                bool idOk              = responseMessage.Id == requestMessage.Id;
                bool statusOk          = responseMessage.Response.Status == Status.Ok;
                bool verifyChallengeOk = client.VerifyNodeChallengeSignature(responseMessage);

                byte[] receivedVersion = responseMessage.Response.ConversationResponse.Start.Version.ToByteArray();
                byte[] expectedVersion = new byte[] { 1, 0, 0 };
                bool   versionOk       = StructuralComparisons.StructuralComparer.Compare(receivedVersion, expectedVersion) == 0;

                bool pubKeyLenOk = responseMessage.Response.ConversationResponse.Start.PublicKey.Length == 32;
                bool challengeOk = responseMessage.Response.ConversationResponse.Start.Challenge.Length == 32;

                Passed = idOk && statusOk && verifyChallengeOk && versionOk && pubKeyLenOk && challengeOk;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            client.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }