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 ServerIp    = (IPAddress)ArgumentValues["Server IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

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

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

                // Step 1
                await client.ConnectAsync(ServerIp, 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.VerifyServerChallengeSignature(responseMessage);
                bool startConversationOk = idOk && statusOk && verifyChallengeOk;

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

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

                responseMessage = await client.ReceiveMessageAsync();

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

                // Step 1 Acceptance

                Passed = startConversationOk && verifyIdentityOk;

                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();
                ByteString myKey          = requestMessage.Request.ConversationRequest.Start.PublicKey;
                byte[]     badChallenge   = new byte[4];
                Crypto.Rng.GetBytes(badChallenge);
                requestMessage.Request.ConversationRequest.Start                 = new StartConversationRequest();
                requestMessage.Request.ConversationRequest.Start.PublicKey       = myKey;
                requestMessage.Request.ConversationRequest.Start.ClientChallenge = ProtocolHelper.ByteArrayToByteString(badChallenge);
                requestMessage.Request.ConversationRequest.Start.SupportedVersions.Add(ProtocolHelper.ByteArrayToByteString(new byte[] { 1, 0, 0 }));

                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

                // Step 1 Acceptance
                bool idOk      = responseMessage.Id == requestMessage.Id;
                bool statusOk  = responseMessage.Response.Status == Status.ErrorInvalidValue;
                bool detailsOk = responseMessage.Response.Details == "clientChallenge";

                Passed = idOk && statusOk && detailsOk;

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

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

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

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

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

                Message    requestMessage = client.CreateStartConversationRequest();
                ByteString myKey          = requestMessage.Request.ConversationRequest.Start.PublicKey;
                ByteString myChallenge    = requestMessage.Request.ConversationRequest.Start.ClientChallenge;
                requestMessage.Request.ConversationRequest.Start                 = new StartConversationRequest();
                requestMessage.Request.ConversationRequest.Start.PublicKey       = myKey;
                requestMessage.Request.ConversationRequest.Start.ClientChallenge = myChallenge;
                requestMessage.Request.ConversationRequest.Start.SupportedVersions.Add(new SemVer(255, 255, 255).ToByteString());
                requestMessage.Request.ConversationRequest.Start.SupportedVersions.Add(new SemVer(255, 255, 254).ToByteString());

                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

                // Step 1 Acceptance
                bool idOk     = responseMessage.Id == requestMessage.Id;
                bool statusOk = responseMessage.Response.Status == Status.ErrorUnsupported;

                Passed = idOk && statusOk;

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

            log.Trace("(-):{0}", res);
            return(res);
        }
Example #4
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);
        }
Example #5
0
    /// <summary>
    /// Implementation of the test itself.
    /// </summary>
    /// <returns>true if the test passes, false otherwise.</returns>
    public override async Task<bool> RunAsync()
    {
      IPAddress ServerIp = (IPAddress)ArgumentValues["Server IP"];
      int ClNonCustomerPort = (int)ArgumentValues["clNonCustomer Port"];
      log.Trace("(ServerIp:'{0}',ClNonCustomerPort:{1})", ServerIp, ClNonCustomerPort);

      bool res = false;
      Passed = false;

      ProtocolClient client = new ProtocolClient();
      try
      {
        MessageBuilder mb = client.MessageBuilder;

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

        Message requestMessage = client.CreateStartConversationRequest();
        byte[] badPubKey = new byte[0];
        requestMessage.Request.ConversationRequest.Start.PublicKey = ProtocolHelper.ByteArrayToByteString(badPubKey);
        await client.SendMessageAsync(requestMessage);
        Message responseMessage = await client.ReceiveMessageAsync();

        bool idOk = responseMessage.Id == requestMessage.Id;
        bool statusOk = responseMessage.Response.Status == Status.ErrorInvalidValue;
        bool detailsOk = responseMessage.Response.Details == "publicKey";

        bool start1Ok = idOk && statusOk && detailsOk;


        requestMessage = client.CreateStartConversationRequest();
        badPubKey = new byte[130];
        for (int i = 0; i < badPubKey.Length; i++)
          badPubKey[i] = 0x40;

        requestMessage.Request.ConversationRequest.Start.PublicKey = ProtocolHelper.ByteArrayToByteString(badPubKey);
        await client.SendMessageAsync(requestMessage);
        responseMessage = await client.ReceiveMessageAsync();

        idOk = responseMessage.Id == requestMessage.Id;
        statusOk = responseMessage.Response.Status == Status.ErrorInvalidValue;
        detailsOk = responseMessage.Response.Details == "publicKey";

        bool start2Ok = idOk && statusOk && detailsOk;

        // Step 1 Acceptance
        bool step1Ok = start1Ok && start2Ok;


        Passed = step1Ok;

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

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