Пример #1
0
        /// <summary>
        /// Selects a common protocol version that both server and client support.
        /// </summary>
        /// <param name="ClientVersions">List of versions that the client supports. The list is ordered by client's preference.</param>
        /// <param name="SelectedCommonVersion">If the function succeeds, this is set to the selected version that both client and server support.</param>
        /// <returns>true if the function succeeds, false otherwise.</returns>
        public bool GetCommonSupportedVersion(IEnumerable <ByteString> ClientVersions, out SemVer SelectedCommonVersion)
        {
            log.Trace("()");
            SelectedCommonVersion = SemVer.Invalid;

            SemVer selectedVersion = SemVer.Invalid;
            bool   res             = false;

            foreach (ByteString clVersion in ClientVersions)
            {
                SemVer version = new SemVer(clVersion);
                if (version.Equals(SemVer.V100))
                {
                    SelectedCommonVersion = version;
                    selectedVersion       = version;
                    res = true;
                    break;
                }
            }

            if (res)
            {
                log.Trace("(-):{0},SelectedCommonVersion='{1}'", res, selectedVersion);
            }
            else
            {
                log.Trace("(-):{0}", res);
            }
            return(res);
        }
Пример #2
0
        /// <summary>
        /// Starts conversation with the server the client is connected to and checks whether the server response contains expected values.
        /// </summary>
        /// <returns>true if the function succeeds, false otherwise.</returns>
        public async Task <bool> StartConversationAsync()
        {
            log.Trace("()");

            PsProtocolMessage requestMessage = CreateStartConversationRequest();

            await SendMessageAsync(requestMessage);

            PsProtocolMessage responseMessage = await ReceiveMessageAsync();

            bool idOk              = responseMessage.Id == requestMessage.Id;
            bool statusOk          = responseMessage.Response.Status == Status.Ok;
            bool challengeVerifyOk = VerifyProfileServerChallengeSignature(responseMessage);

            SemVer receivedVersion = new SemVer(responseMessage.Response.ConversationResponse.Start.Version);
            bool   versionOk       = receivedVersion.Equals(new SemVer(messageBuilder.Version));

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

            profileServerKey = responseMessage.Response.ConversationResponse.Start.PublicKey.ToByteArray();
            challenge        = responseMessage.Response.ConversationResponse.Start.Challenge.ToByteArray();

            bool res = idOk && statusOk && challengeVerifyOk && versionOk && pubKeyLenOk && challengeOk;

            log.Trace("(-):{0}", res);
            return(res);
        }
Пример #3
0
 public void EqualsAndGetHashCode(SemVer value1, SemVer value2, bool expected)
 {
     value1.Equals(value2).Should().Be(expected);
     if (expected)
     {
         value1.GetHashCode().Should().Be(value2.GetHashCode());
     }
     else
     {
         value1.GetHashCode().Should().NotBe(value2.GetHashCode());
     }
 }
Пример #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 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();
                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.VerifyServerChallengeSignature(responseMessage);

                SemVer receivedVersion = new SemVer(responseMessage.Response.ConversationResponse.Start.Version);
                bool   versionOk       = receivedVersion.Equals(SemVer.V100);

                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);
        }
Пример #5
0
        /// <summary>
        /// Starts conversation with the server the client is connected to and checks whether the server response contains expected values.
        /// </summary>
        /// <returns>true if the function succeeds, false otherwise.</returns>
        public async Task <bool> StartConversationAsync()
        {
            log.Trace("()");

            bool res = false;

            Message requestMessage = CreateStartConversationRequest();

            if (await SendMessageAsync(requestMessage))
            {
                Message responseMessage = await ReceiveMessageAsync();

                if (CheckResponseMessage(requestMessage, responseMessage))
                {
                    try
                    {
                        SemVer receivedVersion = new SemVer(responseMessage.Response.ConversationResponse.Start.Version);
                        bool   versionOk       = receivedVersion.Equals(new SemVer(MessageBuilder.Version));

                        bool pubKeyLenOk = responseMessage.Response.ConversationResponse.Start.PublicKey.Length == IdentityBase.IdentifierLength;
                        bool challengeOk = responseMessage.Response.ConversationResponse.Start.Challenge.Length == ProtocolHelper.ChallengeDataSize;

                        serverKey       = responseMessage.Response.ConversationResponse.Start.PublicKey.ToByteArray();
                        serverId        = Crypto.Sha256(serverKey);
                        serverChallenge = responseMessage.Response.ConversationResponse.Start.Challenge.ToByteArray();
                        bool challengeVerifyOk = VerifyServerChallengeSignature(responseMessage);

                        res = versionOk && pubKeyLenOk && challengeOk && challengeVerifyOk;
                    }
                    catch
                    {
                        log.Warn("Received unexpected or invalid message.");
                    }
                }
                else
                {
                    log.Warn("Received unexpected or invalid message.");
                }
            }
            else
            {
                log.Warn("Unable to send message.");
            }

            log.Trace("(-):{0}", res);
            return(res);
        }
Пример #6
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 clientCallee           = new ProtocolClient();
            ProtocolClient clientCalleeAppService = new ProtocolClient(0, SemVer.V100, clientCallee.GetIdentityKeys());

            ProtocolClient clientCaller           = new ProtocolClient();
            ProtocolClient clientCallerAppService = new ProtocolClient(0, SemVer.V100, clientCaller.GetIdentityKeys());

            try
            {
                MessageBuilder mbCallee           = clientCallee.MessageBuilder;
                MessageBuilder mbCalleeAppService = clientCalleeAppService.MessageBuilder;

                MessageBuilder mbCaller           = clientCaller.MessageBuilder;
                MessageBuilder mbCallerAppService = clientCallerAppService.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                // Get port list.
                byte[] pubKeyCallee     = clientCallee.GetIdentityKeys().PublicKey;
                byte[] identityIdCallee = clientCallee.GetIdentityId();

                byte[] pubKeyCaller     = clientCaller.GetIdentityKeys().PublicKey;
                byte[] identityIdCaller = clientCaller.GetIdentityId();


                await clientCallee.ConnectAsync(ServerIp, PrimaryPort, false);

                Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>();
                bool listPortsOk = await clientCallee.ListServerPorts(rolePorts);

                clientCallee.CloseConnection();


                // Establish hosting agreement for identity 1.
                await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHostingOk = await clientCallee.EstablishHostingAsync();

                clientCallee.CloseConnection();


                // Check-in and initialize the profile of identity 1.

                await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                bool checkInOk = await clientCallee.CheckInAsync();

                bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, new GpsLocation(0, 0), null);


                // Add application service to the current session.
                string serviceName     = "Test Service";
                bool   addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName });



                bool firstIdentityOk = listPortsOk && establishHostingOk && checkInOk && initializeProfileOk && addAppServiceOk;



                // Establish hosting agreement for identity 2.
                await clientCaller.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                establishHostingOk = await clientCaller.EstablishHostingAsync();

                clientCaller.CloseConnection();


                // Check-in and initialize the profile of identity 2.

                await clientCaller.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                checkInOk = await clientCaller.CheckInAsync();

                initializeProfileOk = await clientCaller.InitializeProfileAsync("Test Identity", null, new GpsLocation(0, 0), null);


                bool secondIdentityOk = establishHostingOk && checkInOk && initializeProfileOk;



                // Step 1 Acceptance
                bool step1Ok = firstIdentityOk && secondIdentityOk;

                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



                // Step 2
                log.Trace("Step 2");
                Message requestMessage = mbCaller.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName);
                await clientCaller.SendMessageAsync(requestMessage);

                // Step 2 Acceptance
                bool step2Ok = true;

                log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED");



                // Step 3
                log.Trace("Step 3");
                Message serverRequestMessage = await clientCallee.ReceiveMessageAsync();

                byte[] receivedPubKey = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray();
                bool   pubKeyOk       = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller) == 0;
                bool   serviceNameOk  = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName;

                bool incomingCallNotificationOk = pubKeyOk && serviceNameOk;

                byte[] calleeToken = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray();

                Message serverResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(serverRequestMessage);
                await clientCallee.SendMessageAsync(serverResponseMessage);


                // Connect to clAppService and send initialization message.
                await clientCalleeAppService.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, null);
                await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee);


                // Step 3 Acceptance
                bool step3Ok = incomingCallNotificationOk;

                log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED");


                // Step 4
                log.Trace("Step 4");
                Message responseMessage = await clientCaller.ReceiveMessageAsync();

                bool   idOk        = responseMessage.Id == requestMessage.Id;
                bool   statusOk    = responseMessage.Response.Status == Status.Ok;
                byte[] callerToken = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray();

                bool callIdentityOk = idOk && statusOk;

                // Connect to clAppService and send initialization message.
                await clientCallerAppService.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, null);
                await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);

                Message responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id;
                statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok;

                bool initAppServiceMessageOk = idOk && statusOk;



                // Step 4 Acceptance
                bool step4Ok = callIdentityOk && initAppServiceMessageOk;

                log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED");



                // Step 5
                log.Trace("Step 5");
                Message responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id;
                statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok;

                bool typeOk = (responseMessageAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Response) &&
                              (responseMessageAppServiceCallee.Response.ConversationTypeCase == Response.ConversationTypeOneofCase.SingleResponse) &&
                              (responseMessageAppServiceCallee.Response.SingleResponse.ResponseTypeCase == SingleResponse.ResponseTypeOneofCase.ApplicationServiceSendMessage);

                bool appServiceSendOk = idOk && statusOk && typeOk;

                // Step 5 Acceptance
                bool step5Ok = appServiceSendOk;

                log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED");


                // Step 6
                log.Trace("Step 6");
                string callerMessage1 = "Message #1 to callee.";
                byte[] messageBytes   = Encoding.UTF8.GetBytes(callerMessage1);
                requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, messageBytes);
                uint callerMessage1Id = requestMessageAppServiceCaller.Id;
                await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);

                string callerMessage2 = "Message #2 to callee.";
                messageBytes = Encoding.UTF8.GetBytes(callerMessage2);
                requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, messageBytes);
                uint callerMessage2Id = requestMessageAppServiceCaller.Id;
                await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);

                string callerMessage3 = "Message #3 to callee.";
                messageBytes = Encoding.UTF8.GetBytes(callerMessage3);
                requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, messageBytes);
                uint callerMessage3Id = requestMessageAppServiceCaller.Id;
                await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);


                // Step 6 Acceptance
                bool step6Ok = true;

                log.Trace("Step 6: {0}", step6Ok ? "PASSED" : "FAILED");


                // Step 8
                log.Trace("Step 7");
                // Receive message #1.
                Message serverRequestAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                SemVer receivedVersion = new SemVer(serverRequestAppServiceCallee.Request.SingleRequest.Version);
                bool   versionOk       = receivedVersion.Equals(SemVer.V100);

                typeOk = (serverRequestAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Request) &&
                         (serverRequestAppServiceCallee.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) &&
                         (serverRequestAppServiceCallee.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification);

                string receivedMessage = Encoding.UTF8.GetString(serverRequestAppServiceCallee.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray());
                bool   messageOk       = receivedMessage == callerMessage1;

                bool receiveMessageOk1 = versionOk && typeOk && messageOk;


                // ACK message #1.
                Message serverResponseAppServiceCallee = mbCalleeAppService.CreateApplicationServiceReceiveMessageNotificationResponse(serverRequestAppServiceCallee);
                await clientCalleeAppService.SendMessageAsync(serverResponseAppServiceCallee);


                // Receive message #2.
                serverRequestAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                receivedVersion = new SemVer(serverRequestAppServiceCallee.Request.SingleRequest.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                typeOk = (serverRequestAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Request) &&
                         (serverRequestAppServiceCallee.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) &&
                         (serverRequestAppServiceCallee.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification);

                receivedMessage = Encoding.UTF8.GetString(serverRequestAppServiceCallee.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray());
                messageOk       = receivedMessage == callerMessage2;

                bool receiveMessageOk2 = versionOk && typeOk && messageOk;


                // ACK message #2.
                serverResponseAppServiceCallee = mbCalleeAppService.CreateApplicationServiceReceiveMessageNotificationResponse(serverRequestAppServiceCallee);
                await clientCalleeAppService.SendMessageAsync(serverResponseAppServiceCallee);


                // Send our message #1.
                string calleeMessage1 = "Message #1 to CALLER.";
                messageBytes = Encoding.UTF8.GetBytes(calleeMessage1);
                requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, messageBytes);
                uint calleeMessage1Id = requestMessageAppServiceCallee.Id;
                await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee);


                // Receive message #3.
                serverRequestAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                receivedVersion = new SemVer(serverRequestAppServiceCallee.Request.SingleRequest.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                typeOk = (serverRequestAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Request) &&
                         (serverRequestAppServiceCallee.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) &&
                         (serverRequestAppServiceCallee.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification);

                receivedMessage = Encoding.UTF8.GetString(serverRequestAppServiceCallee.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray());
                messageOk       = receivedMessage == callerMessage3;

                bool receiveMessageOk3 = versionOk && typeOk && messageOk;


                // ACK message #2.
                serverResponseAppServiceCallee = mbCalleeAppService.CreateApplicationServiceReceiveMessageNotificationResponse(serverRequestAppServiceCallee);
                await clientCalleeAppService.SendMessageAsync(serverResponseAppServiceCallee);



                // Send our message #2.
                string calleeMessage2 = "Message #2 to CALLER.";
                messageBytes = Encoding.UTF8.GetBytes(calleeMessage2);
                requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, messageBytes);
                uint calleeMessage2Id = requestMessageAppServiceCallee.Id;
                await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee);

                await Task.Delay(3000);


                // Step 7 Acceptance
                bool step7Ok = receiveMessageOk1 && receiveMessageOk2 && receiveMessageOk3;

                log.Trace("Step 7: {0}", step7Ok ? "PASSED" : "FAILED");



                // Step 8
                log.Trace("Step 8");
                // Receive ACK message #1.
                responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync();

                idOk            = responseMessageAppServiceCaller.Id == callerMessage1Id;
                statusOk        = responseMessageAppServiceCaller.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessageAppServiceCaller.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                bool receiveAck1Ok = idOk && statusOk && versionOk;



                // Receive ACK message #2.
                responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync();

                idOk            = responseMessageAppServiceCaller.Id == callerMessage2Id;
                statusOk        = responseMessageAppServiceCaller.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessageAppServiceCaller.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                bool receiveAck2Ok = idOk && statusOk && versionOk;



                // Receive message #1 from callee.
                Message serverRequestAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync();

                receivedVersion = new SemVer(serverRequestAppServiceCaller.Request.SingleRequest.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                typeOk = (serverRequestAppServiceCaller.MessageTypeCase == Message.MessageTypeOneofCase.Request) &&
                         (serverRequestAppServiceCaller.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) &&
                         (serverRequestAppServiceCaller.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification);

                receivedMessage = Encoding.UTF8.GetString(serverRequestAppServiceCaller.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray());
                messageOk       = receivedMessage == calleeMessage1;

                receiveMessageOk1 = versionOk && typeOk && messageOk;



                // ACK message #1 from callee.
                Message serverResponseAppServiceCaller = mbCallerAppService.CreateApplicationServiceReceiveMessageNotificationResponse(serverRequestAppServiceCaller);
                await clientCallerAppService.SendMessageAsync(serverResponseAppServiceCaller);



                // Receive ACK message #3.
                responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync();

                idOk            = responseMessageAppServiceCaller.Id == callerMessage3Id;
                statusOk        = responseMessageAppServiceCaller.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessageAppServiceCaller.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                bool receiveAck3Ok = idOk && statusOk && versionOk;



                // Receive message #2 from callee.
                serverRequestAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync();

                receivedVersion = new SemVer(serverRequestAppServiceCaller.Request.SingleRequest.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                typeOk = (serverRequestAppServiceCaller.MessageTypeCase == Message.MessageTypeOneofCase.Request) &&
                         (serverRequestAppServiceCaller.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) &&
                         (serverRequestAppServiceCaller.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification);

                receivedMessage = Encoding.UTF8.GetString(serverRequestAppServiceCaller.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray());
                messageOk       = receivedMessage == calleeMessage2;

                receiveMessageOk2 = versionOk && typeOk && messageOk;



                // ACK message #2 from callee.
                serverResponseAppServiceCaller = mbCallerAppService.CreateApplicationServiceReceiveMessageNotificationResponse(serverRequestAppServiceCaller);
                await clientCallerAppService.SendMessageAsync(serverResponseAppServiceCaller);


                // Step 8 Acceptance
                bool step8Ok = receiveAck1Ok && receiveAck2Ok && receiveMessageOk1 && receiveAck3Ok && receiveMessageOk2;

                log.Trace("Step 8: {0}", step8Ok ? "PASSED" : "FAILED");



                // Step 9
                log.Trace("Step 9");

                // Receive ACK message #1.
                responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                idOk            = responseMessageAppServiceCallee.Id == calleeMessage1Id;
                statusOk        = responseMessageAppServiceCallee.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessageAppServiceCallee.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                receiveAck1Ok = idOk && statusOk && versionOk;

                // Receive ACK message #2.
                responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                idOk            = responseMessageAppServiceCallee.Id == calleeMessage2Id;
                statusOk        = responseMessageAppServiceCallee.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessageAppServiceCallee.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                receiveAck2Ok = idOk && statusOk && versionOk;


                // Step 9 Acceptance
                bool step9Ok = receiveAck1Ok && receiveAck2Ok;

                log.Trace("Step 9: {0}", step9Ok ? "PASSED" : "FAILED");


                Passed = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok && step7Ok && step8Ok && step9Ok;

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

            log.Trace("(-):{0}", res);
            return(res);
        }
Пример #7
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"];
            int       ClCustomerPort    = (int)ArgumentValues["clCustomer Port"];

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

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb             = client.MessageBuilder;
                byte[]         testPubKey     = client.GetIdentityKeys().PublicKey;
                byte[]         testIdentityId = client.GetIdentityId();

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

                bool establishHostingOk = await client.EstablishHostingAsync();

                // Step 1 Acceptance
                bool step1Ok = establishHostingOk;
                client.CloseConnection();


                // Step 2
                await client.ConnectAsync(ServerIp, ClCustomerPort, true);

                bool checkInOk = await client.CheckInAsync();

                Message requestMessage = mb.CreateUpdateProfileRequest(SemVer.V100, "Test Identity", null, new GpsLocation(1, 2), null);
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

                bool idOk     = responseMessage.Id == requestMessage.Id;
                bool statusOk = responseMessage.Response.Status == Status.Ok;

                bool updateProfileOk = idOk && statusOk;


                requestMessage = mb.CreateGetIdentityInformationRequest(testIdentityId);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;
                bool isHostedOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsHosted;
                bool isOnlineOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsOnline;

                byte[] receivedPubKey  = responseMessage.Response.SingleResponse.GetIdentityInformation.IdentityPublicKey.ToByteArray();
                bool   pubKeyOk        = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, testPubKey) == 0;
                SemVer receivedVersion = new SemVer(responseMessage.Response.SingleResponse.GetIdentityInformation.Version);
                bool   versionOk       = receivedVersion.Equals(SemVer.V100);

                bool nameOk      = responseMessage.Response.SingleResponse.GetIdentityInformation.Name == "Test Identity";
                bool extraDataOk = responseMessage.Response.SingleResponse.GetIdentityInformation.ExtraData == "";
                bool locationOk  = responseMessage.Response.SingleResponse.GetIdentityInformation.Latitude == 1 &&
                                   responseMessage.Response.SingleResponse.GetIdentityInformation.Longitude == 2;

                bool getIdentityInfoOk = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && versionOk && nameOk && extraDataOk && locationOk;


                byte[] imageData = File.ReadAllBytes(string.Format("images{0}PS04006.jpg", Path.DirectorySeparatorChar));
                requestMessage = mb.CreateUpdateProfileRequest(null, "Test Identity Renamed", imageData, new GpsLocation(-1, -2), "a=b");
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool updateProfileOk2 = idOk && statusOk;


                requestMessage = mb.CreateGetIdentityInformationRequest(testIdentityId, true, true, false);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk       = responseMessage.Id == requestMessage.Id;
                statusOk   = responseMessage.Response.Status == Status.Ok;
                isHostedOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsHosted;
                isOnlineOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsOnline;

                receivedPubKey  = responseMessage.Response.SingleResponse.GetIdentityInformation.IdentityPublicKey.ToByteArray();
                pubKeyOk        = StructuralComparisons.StructuralComparer.Compare(testPubKey, receivedPubKey) == 0;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.GetIdentityInformation.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                nameOk      = responseMessage.Response.SingleResponse.GetIdentityInformation.Name == "Test Identity Renamed";
                extraDataOk = responseMessage.Response.SingleResponse.GetIdentityInformation.ExtraData == "a=b";
                locationOk  = responseMessage.Response.SingleResponse.GetIdentityInformation.Latitude == -1 &&
                              responseMessage.Response.SingleResponse.GetIdentityInformation.Longitude == -2;


                byte[] receivedProfileImage   = responseMessage.Response.SingleResponse.GetIdentityInformation.ProfileImage.ToByteArray();
                bool   profileImageOk         = StructuralComparisons.StructuralComparer.Compare(receivedProfileImage, imageData) == 0;
                byte[] receivedThumbnailImage = responseMessage.Response.SingleResponse.GetIdentityInformation.ThumbnailImage.ToByteArray();
                bool   thumbnailImageOk       = receivedThumbnailImage.Length > 0;

                bool getIdentityInfoOk2 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && versionOk && nameOk && extraDataOk && locationOk && profileImageOk && thumbnailImageOk;



                imageData      = new byte[] { };
                requestMessage = mb.CreateUpdateProfileRequest(null, null, imageData, null, null);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool updateProfileOk3 = idOk && statusOk;



                requestMessage = mb.CreateGetIdentityInformationRequest(testIdentityId, true, true, false);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk       = responseMessage.Id == requestMessage.Id;
                statusOk   = responseMessage.Response.Status == Status.Ok;
                isHostedOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsHosted;
                isOnlineOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsOnline;

                receivedPubKey  = responseMessage.Response.SingleResponse.GetIdentityInformation.IdentityPublicKey.ToByteArray();
                pubKeyOk        = StructuralComparisons.StructuralComparer.Compare(testPubKey, receivedPubKey) == 0;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.GetIdentityInformation.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                nameOk      = responseMessage.Response.SingleResponse.GetIdentityInformation.Name == "Test Identity Renamed";
                extraDataOk = responseMessage.Response.SingleResponse.GetIdentityInformation.ExtraData == "a=b";
                locationOk  = responseMessage.Response.SingleResponse.GetIdentityInformation.Latitude == -1 &&
                              responseMessage.Response.SingleResponse.GetIdentityInformation.Longitude == -2;


                receivedProfileImage   = responseMessage.Response.SingleResponse.GetIdentityInformation.ProfileImage.ToByteArray();
                profileImageOk         = receivedProfileImage.Length == 0;
                receivedThumbnailImage = responseMessage.Response.SingleResponse.GetIdentityInformation.ThumbnailImage.ToByteArray();
                thumbnailImageOk       = receivedThumbnailImage.Length == 0;

                bool getIdentityInfoOk3 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && versionOk && nameOk && extraDataOk && locationOk && profileImageOk && thumbnailImageOk;



                // Step 2 Acceptance
                bool step2Ok = checkInOk && updateProfileOk && getIdentityInfoOk && updateProfileOk2 && getIdentityInfoOk2 && updateProfileOk3 && getIdentityInfoOk3;


                Passed = step1Ok && step2Ok;

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

            log.Trace("(-):{0}", res);
            return(res);
        }
Пример #8
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 clientCallee           = new ProtocolClient();
            ProtocolClient clientCalleeAppService = new ProtocolClient(0, SemVer.V100, clientCallee.GetIdentityKeys());

            ProtocolClient clientCaller           = new ProtocolClient();
            ProtocolClient clientCallerAppService = new ProtocolClient(0, SemVer.V100, clientCaller.GetIdentityKeys());

            try
            {
                MessageBuilder mbCallee           = clientCallee.MessageBuilder;
                MessageBuilder mbCalleeAppService = clientCalleeAppService.MessageBuilder;

                MessageBuilder mbCaller           = clientCaller.MessageBuilder;
                MessageBuilder mbCallerAppService = clientCallerAppService.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                // Get port list.
                byte[] pubKeyCallee     = clientCallee.GetIdentityKeys().PublicKey;
                byte[] identityIdCallee = clientCallee.GetIdentityId();

                byte[] pubKeyCaller     = clientCaller.GetIdentityKeys().PublicKey;
                byte[] identityIdCaller = clientCaller.GetIdentityId();


                await clientCallee.ConnectAsync(ServerIp, PrimaryPort, false);

                Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>();
                bool listPortsOk = await clientCallee.ListServerPorts(rolePorts);

                clientCallee.CloseConnection();


                // Establish hosting agreement for identity 1.
                await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHostingOk = await clientCallee.EstablishHostingAsync();

                clientCallee.CloseConnection();


                // Check-in and initialize the profile of identity 1.

                await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                bool checkInOk = await clientCallee.CheckInAsync();

                bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, new GpsLocation(0, 0), null);


                // Add application service to the current session.
                string serviceName     = "Test Service";
                bool   addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName });


                // Step 1 Acceptance
                bool step1Ok = listPortsOk && establishHostingOk && checkInOk && initializeProfileOk && addAppServiceOk;

                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



                // Step 2
                log.Trace("Step 2");
                await clientCaller.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool verifyIdentityOk = await clientCaller.VerifyIdentityAsync();

                Message requestMessage = mbCaller.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName);
                await clientCaller.SendMessageAsync(requestMessage);


                // Step 2 Acceptance
                bool step2Ok = verifyIdentityOk;

                log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED");



                // Step 3
                log.Trace("Step 3");
                Message serverRequestMessage = await clientCallee.ReceiveMessageAsync();

                byte[] receivedPubKey = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray();
                bool   pubKeyOk       = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller) == 0;
                bool   serviceNameOk  = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName;

                bool incomingCallNotificationOk = pubKeyOk && serviceNameOk;

                byte[] calleeToken = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray();

                Message serverResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(serverRequestMessage);
                await clientCallee.SendMessageAsync(serverResponseMessage);


                // Connect to clAppService and send initialization message.
                await clientCalleeAppService.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, null);
                await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee);


                // Step 3 Acceptance
                bool step3Ok = incomingCallNotificationOk;

                log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED");



                // Step 4
                log.Trace("Step 4");
                Message responseMessage = await clientCaller.ReceiveMessageAsync();

                bool   idOk        = responseMessage.Id == requestMessage.Id;
                bool   statusOk    = responseMessage.Response.Status == Status.Ok;
                byte[] callerToken = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray();

                bool callIdentityOk = idOk && statusOk;

                // Connect to clAppService and send initialization message.
                await clientCallerAppService.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, null);
                await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);

                Message responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id;
                statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok;

                bool initAppServiceMessageOk = idOk && statusOk;

                clientCaller.CloseConnection();


                // Step 4 Acceptance
                bool step4Ok = callIdentityOk && initAppServiceMessageOk;

                log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED");



                // Step 5
                log.Trace("Step 5");
                Message responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id;
                statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok;

                bool appServiceSendOk = idOk && statusOk;


                // Step 5 Acceptance
                bool step5Ok = appServiceSendOk;

                log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED");



                // Step 6
                log.Trace("Step 6");

                bool error             = false;
                int  messagesDelivered = 0;
                int  messagesSent      = 0;
                bool disconnectedOk    = false;
                for (int i = 0; i < 20; i++)
                {
                    try
                    {
                        // Caller sends message.
                        string callerMessage = string.Format("Message #{0} to callee.", i + 1);
                        byte[] messageBytes  = Encoding.UTF8.GetBytes(callerMessage);
                        requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, messageBytes);
                        await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);

                        messagesSent++;


                        // Callee receives message.
                        Message serverRequestAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                        SemVer receivedVersion = new SemVer(serverRequestAppServiceCallee.Request.SingleRequest.Version);
                        bool   versionOk       = receivedVersion.Equals(SemVer.V100);

                        bool typeOk = (serverRequestAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Request) &&
                                      (serverRequestAppServiceCallee.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) &&
                                      (serverRequestAppServiceCallee.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification);

                        string receivedMessage = Encoding.UTF8.GetString(serverRequestAppServiceCallee.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray());
                        bool   messageOk       = receivedMessage == callerMessage;

                        bool receiveMessageOk = versionOk && typeOk && messageOk;

                        if (receiveMessageOk)
                        {
                            messagesDelivered++;
                            log.Trace("Delivery of message #{0} succeeded.", i + 1);
                        }
                        else
                        {
                            log.Trace("Delivery of message #{0} failed.", i + 1);
                            error = true;
                            break;
                        }

                        await Task.Delay(10 * 1000);
                    }
                    catch
                    {
                        log.Trace("Expected exception occurred.");
                        disconnectedOk = true;
                        break;
                    }
                }



                // Step 6 Acceptance
                bool step6Ok = !error && disconnectedOk && (messagesDelivered < 20);

                log.Trace("Step 6: {0}", step6Ok ? "PASSED" : "FAILED");


                Passed = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok;

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

            log.Trace("(-):{0}", res);
            return(res);
        }
        /// <summary>
        /// Validates ActivityInformation structure by itself. This function does not touch database and does not validate
        /// anything that depends on the context.
        /// </summary>
        /// <param name="Activity">Description of the activity to validate.</param>
        /// <param name="OwnerIdentityPublicKey">Public key of the activity's owner identity.</param>
        /// <param name="MessageBuilder">Network message builder of the client who sent this activity description.</param>
        /// <param name="RequestMessage">Full request message from client.</param>
        /// <param name="ErrorPrefix">Prefix to add to the validation error details.</param>
        /// <param name="ErrorResponse">If the function fails, this is filled with error response message that is ready to be sent to the client.</param>
        /// <returns>true if the activity information is valid, false otherwise.</returns>
        public static bool ValidateActivityInformation(ActivityInformation Activity, byte[] OwnerIdentityPublicKey, ProxMessageBuilder MessageBuilder, ProxProtocolMessage RequestMessage, string ErrorPrefix, out ProxProtocolMessage ErrorResponse)
        {
            log.Trace("()");

            bool res = false;

            ErrorResponse = null;
            string details = null;

            if (Activity == null)
            {
                Activity = new ActivityInformation();
            }
            if (Activity.ProfileServerContact == null)
            {
                Activity.ProfileServerContact = new ServerContactInfo();
            }

            SemVer version = new SemVer(Activity.Version);

            // Currently only supported version is 1.0.0.
            if (!version.Equals(SemVer.V100))
            {
                log.Debug("Unsupported version '{0}'.", version);
                details = "version";
            }


            if (details == null)
            {
                uint activityId = Activity.Id;

                // 0 is not a valid activity identifier.
                if (activityId == 0)
                {
                    log.Debug("Invalid activity ID '{0}'.", activityId);
                    details = "id";
                }
            }

            if (details == null)
            {
                byte[] pubKey      = Activity.OwnerPublicKey.ToByteArray();
                bool   pubKeyValid = (0 < pubKey.Length) && (pubKey.Length <= ProtocolHelper.MaxPublicKeyLengthBytes) && ByteArrayComparer.Equals(OwnerIdentityPublicKey, pubKey);
                if (!pubKeyValid)
                {
                    log.Debug("Invalid public key '{0}' does not match identity public key '{1}'.", pubKey.ToHex(), OwnerIdentityPublicKey.ToHex());
                    details = "ownerPublicKey";
                }
            }


            if (details == null)
            {
                ServerContactInfo sci    = Activity.ProfileServerContact;
                bool      networkIdValid = sci.NetworkId.Length == ProtocolHelper.NetworkIdentifierLength;
                IPAddress ipAddress      = IPAddressExtensions.IpFromBytes(sci.IpAddress.ToByteArray());
                bool      ipAddressValid = (ipAddress != null) && (Config.Configuration.TestModeEnabled || !ipAddress.IsReservedOrLocal());
                bool      portValid      = (1 <= sci.PrimaryPort) && (sci.PrimaryPort <= 65535);

                if (!networkIdValid || !ipAddressValid || !portValid)
                {
                    log.Debug("Profile server contact's network ID is {0}, IP address is {1}, port is {2}.", networkIdValid ? "valid" : "invalid", ipAddressValid ? "valid" : "invalid", portValid ? "valid" : "invalid");

                    if (!networkIdValid)
                    {
                        details = "profileServerContact.networkId";
                    }
                    else if (!ipAddressValid)
                    {
                        details = "profileServerContact.ipAddress";
                    }
                    else if (!portValid)
                    {
                        details = "profileServerContact.primaryPort";
                    }
                }
            }

            if (details == null)
            {
                string activityType = Activity.Type;
                if (activityType == null)
                {
                    activityType = "";
                }

                int  byteLen           = Encoding.UTF8.GetByteCount(activityType);
                bool activityTypeValid = (0 < byteLen) && (byteLen <= ProxMessageBuilder.MaxActivityTypeLengthBytes);
                if (!activityTypeValid)
                {
                    log.Debug("Activity type too long or zero length ({0} bytes, limit is {1}).", byteLen, ProxMessageBuilder.MaxActivityTypeLengthBytes);
                    details = "type";
                }
            }

            if (details == null)
            {
                GpsLocation locLat  = new GpsLocation(Activity.Latitude, 0);
                GpsLocation locLong = new GpsLocation(0, Activity.Longitude);
                if (!locLat.IsValid())
                {
                    log.Debug("Latitude '{0}' is not a valid GPS latitude value.", Activity.Latitude);
                    details = "latitude";
                }
                else if (!locLong.IsValid())
                {
                    log.Debug("Longitude '{0}' is not a valid GPS longitude value.", Activity.Longitude);
                    details = "longitude";
                }
            }

            if (details == null)
            {
                uint precision      = Activity.Precision;
                bool precisionValid = (0 <= precision) && (precision <= ProxMessageBuilder.MaxLocationPrecision);
                if (!precisionValid)
                {
                    log.Debug("Precision '{0}' is not an integer between 0 and {1}.", precision, ProxMessageBuilder.MaxLocationPrecision);
                    details = "precision";
                }
            }


            if (details == null)
            {
                DateTime?startTime      = ProtocolHelper.UnixTimestampMsToDateTime(Activity.StartTime);
                DateTime?expirationTime = ProtocolHelper.UnixTimestampMsToDateTime(Activity.ExpirationTime);

                if (startTime == null)
                {
                    log.Debug("Invalid activity start time timestamp '{0}'.", Activity.StartTime);
                    details = "startTime";
                }
                else if (expirationTime == null)
                {
                    log.Debug("Invalid activity expiration time timestamp '{0}'.", Activity.ExpirationTime);
                    details = "expirationTime";
                }
                else
                {
                    if (startTime > expirationTime)
                    {
                        log.Debug("Activity expiration time has to be greater than or equal to its start time.");
                        details = "expirationTime";
                    }
                    else if (expirationTime.Value > DateTime.UtcNow.AddHours(ActivityBase.MaxActivityLifeTimeHours))
                    {
                        log.Debug("Activity expiration time {0} is more than {1} hours in the future.", expirationTime.Value.ToString("yyyy-MM-dd HH:mm:ss"), ActivityBase.MaxActivityLifeTimeHours);
                        details = "expirationTime";
                    }
                }
            }

            if (details == null)
            {
                string extraData = Activity.ExtraData;
                if (extraData == null)
                {
                    extraData = "";
                }


                // Extra data is semicolon separated 'key=value' list, max ActivityBase.MaxActivityExtraDataLengthBytes bytes long.
                int byteLen = Encoding.UTF8.GetByteCount(extraData);
                if (byteLen > ProxMessageBuilder.MaxActivityExtraDataLengthBytes)
                {
                    log.Debug("Extra data too large ({0} bytes, limit is {1}).", byteLen, ProxMessageBuilder.MaxActivityExtraDataLengthBytes);
                    details = "extraData";
                }
            }

            if (details == null)
            {
                res = true;
            }
            else
            {
                ErrorResponse = MessageBuilder.CreateErrorInvalidValueResponse(RequestMessage, ErrorPrefix + details);
            }

            log.Trace("(-):{0}", res);
            return(res);
        }
Пример #10
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"];
            int       ClCustomerPort    = (int)ArgumentValues["clCustomer Port"];

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

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb             = client.MessageBuilder;
                byte[]         testPubKey     = client.GetIdentityKeys().PublicKey;
                byte[]         testIdentityId = client.GetIdentityId();

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

                bool establishHostingOk = await client.EstablishHostingAsync();

                // Step 1 Acceptance
                bool step1Ok = establishHostingOk;
                client.CloseConnection();


                // Step 2
                await client.ConnectAsync(ServerIp, ClCustomerPort, true);

                bool checkInOk = await client.CheckInAsync();


                Message requestMessage = mb.CreateUpdateProfileRequest(SemVer.V100, "Test Identity", null, new GpsLocation(0, 0), null);
                await client.SendMessageAsync(requestMessage);

                Message responseMessage = await client.ReceiveMessageAsync();

                bool idOk     = responseMessage.Id == requestMessage.Id;
                bool statusOk = responseMessage.Response.Status == Status.Ok;

                bool updateProfileOk = idOk && statusOk;



                List <string> asList = new List <string>()
                {
                    "a", "b", "c", "d", "a"
                };
                requestMessage = mb.CreateApplicationServiceAddRequest(asList);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool appServiceAddOk1 = idOk && statusOk;


                requestMessage = mb.CreateGetIdentityInformationRequest(testIdentityId, false, false, true);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;
                bool isHostedOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsHosted;
                bool isOnlineOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsOnline;

                byte[] receivedPubKey  = responseMessage.Response.SingleResponse.GetIdentityInformation.IdentityPublicKey.ToByteArray();
                bool   pubKeyOk        = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, testPubKey) == 0;
                SemVer receivedVersion = new SemVer(responseMessage.Response.SingleResponse.GetIdentityInformation.Version);
                bool   versionOk       = receivedVersion.Equals(SemVer.V100);

                HashSet <string> expectedAsList = new HashSet <string>(StringComparer.Ordinal)
                {
                    "a", "b", "c", "d"
                };
                HashSet <string> receivedAsList = new HashSet <string>(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices, StringComparer.Ordinal);
                bool             appServicesOk  = expectedAsList.SetEquals(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices);


                bool getIdentityInfoOk1 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && versionOk && appServicesOk;



                asList = new List <string>()
                {
                    "c", "d", "a", "e"
                };
                requestMessage = mb.CreateApplicationServiceAddRequest(asList);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool appServiceAddOk2 = idOk && statusOk;


                requestMessage = mb.CreateGetIdentityInformationRequest(testIdentityId, false, false, true);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk       = responseMessage.Id == requestMessage.Id;
                statusOk   = responseMessage.Response.Status == Status.Ok;
                isHostedOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsHosted;
                isOnlineOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsOnline;

                receivedPubKey  = responseMessage.Response.SingleResponse.GetIdentityInformation.IdentityPublicKey.ToByteArray();
                pubKeyOk        = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, testPubKey) == 0;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.GetIdentityInformation.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                expectedAsList = new HashSet <string>(StringComparer.Ordinal)
                {
                    "a", "b", "c", "d", "e"
                };
                receivedAsList = new HashSet <string>(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices, StringComparer.Ordinal);
                appServicesOk  = expectedAsList.SetEquals(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices);


                bool getIdentityInfoOk2 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && versionOk && appServicesOk;



                requestMessage = mb.CreateApplicationServiceRemoveRequest("a");
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool appServiceRemoveOk3 = idOk && statusOk;


                requestMessage = mb.CreateGetIdentityInformationRequest(testIdentityId, false, false, true);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk       = responseMessage.Id == requestMessage.Id;
                statusOk   = responseMessage.Response.Status == Status.Ok;
                isHostedOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsHosted;
                isOnlineOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsOnline;

                receivedPubKey  = responseMessage.Response.SingleResponse.GetIdentityInformation.IdentityPublicKey.ToByteArray();
                pubKeyOk        = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, testPubKey) == 0;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.GetIdentityInformation.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                expectedAsList = new HashSet <string>(StringComparer.Ordinal)
                {
                    "b", "c", "d", "e"
                };
                receivedAsList = new HashSet <string>(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices, StringComparer.Ordinal);
                appServicesOk  = expectedAsList.SetEquals(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices);


                bool getIdentityInfoOk3 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && versionOk && appServicesOk;



                requestMessage = mb.CreateApplicationServiceRemoveRequest("a");
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.ErrorNotFound;

                bool appServiceRemoveOk4 = idOk && statusOk;


                requestMessage = mb.CreateGetIdentityInformationRequest(testIdentityId, false, false, true);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk       = responseMessage.Id == requestMessage.Id;
                statusOk   = responseMessage.Response.Status == Status.Ok;
                isHostedOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsHosted;
                isOnlineOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsOnline;

                receivedPubKey  = responseMessage.Response.SingleResponse.GetIdentityInformation.IdentityPublicKey.ToByteArray();
                pubKeyOk        = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, testPubKey) == 0;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.GetIdentityInformation.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                expectedAsList = new HashSet <string>(StringComparer.Ordinal)
                {
                    "b", "c", "d", "e"
                };
                receivedAsList = new HashSet <string>(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices, StringComparer.Ordinal);
                appServicesOk  = expectedAsList.SetEquals(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices);


                bool getIdentityInfoOk4 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && versionOk && appServicesOk;



                asList = new List <string>()
                {
                    "d", "1234567890-1234567890-1234567890-1234567890", "a", "e"
                };
                requestMessage = mb.CreateApplicationServiceAddRequest(asList);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.ErrorInvalidValue;
                bool detailsOk = responseMessage.Response.Details == "serviceNames[1]";

                bool appServiceAddOk5 = idOk && statusOk && detailsOk;


                requestMessage = mb.CreateGetIdentityInformationRequest(testIdentityId, false, false, true);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk       = responseMessage.Id == requestMessage.Id;
                statusOk   = responseMessage.Response.Status == Status.Ok;
                isHostedOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsHosted;
                isOnlineOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsOnline;

                receivedPubKey  = responseMessage.Response.SingleResponse.GetIdentityInformation.IdentityPublicKey.ToByteArray();
                pubKeyOk        = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, testPubKey) == 0;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.GetIdentityInformation.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                expectedAsList = new HashSet <string>(StringComparer.Ordinal)
                {
                    "b", "c", "d", "e"
                };
                receivedAsList = new HashSet <string>(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices, StringComparer.Ordinal);
                appServicesOk  = expectedAsList.SetEquals(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices);


                bool getIdentityInfoOk5 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && versionOk && appServicesOk;



                asList = new List <string>()
                {
                    "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10"
                };
                requestMessage = mb.CreateApplicationServiceAddRequest(asList);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool appServiceAddOk6 = idOk && statusOk;


                asList = new List <string>()
                {
                    "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "b10"
                };
                requestMessage = mb.CreateApplicationServiceAddRequest(asList);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool appServiceAddOk7 = idOk && statusOk;



                requestMessage = mb.CreateGetIdentityInformationRequest(testIdentityId, false, false, true);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk       = responseMessage.Id == requestMessage.Id;
                statusOk   = responseMessage.Response.Status == Status.Ok;
                isHostedOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsHosted;
                isOnlineOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsOnline;

                receivedPubKey  = responseMessage.Response.SingleResponse.GetIdentityInformation.IdentityPublicKey.ToByteArray();
                pubKeyOk        = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, testPubKey) == 0;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.GetIdentityInformation.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                expectedAsList = new HashSet <string>(StringComparer.Ordinal)
                {
                    "b", "c", "d", "e", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "b10"
                };
                receivedAsList = new HashSet <string>(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices, StringComparer.Ordinal);
                appServicesOk  = expectedAsList.SetEquals(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices);


                bool getIdentityInfoOk7 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && versionOk && appServicesOk;



                asList = new List <string>()
                {
                    "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "d10", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "e10"
                };
                requestMessage = mb.CreateApplicationServiceAddRequest(asList);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.ErrorQuotaExceeded;

                bool appServiceAddOk8 = idOk && statusOk;


                requestMessage = mb.CreateGetIdentityInformationRequest(testIdentityId, false, false, true);
                await client.SendMessageAsync(requestMessage);

                responseMessage = await client.ReceiveMessageAsync();

                idOk       = responseMessage.Id == requestMessage.Id;
                statusOk   = responseMessage.Response.Status == Status.Ok;
                isHostedOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsHosted;
                isOnlineOk = responseMessage.Response.SingleResponse.GetIdentityInformation.IsOnline;

                receivedPubKey  = responseMessage.Response.SingleResponse.GetIdentityInformation.IdentityPublicKey.ToByteArray();
                pubKeyOk        = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, testPubKey) == 0;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.GetIdentityInformation.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                expectedAsList = new HashSet <string>(StringComparer.Ordinal)
                {
                    "b", "c", "d", "e", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "b10"
                };
                receivedAsList = new HashSet <string>(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices, StringComparer.Ordinal);
                appServicesOk  = expectedAsList.SetEquals(responseMessage.Response.SingleResponse.GetIdentityInformation.ApplicationServices);


                bool getIdentityInfoOk8 = idOk && statusOk && isHostedOk && isOnlineOk && pubKeyOk && versionOk && appServicesOk;


                // Step 2 Acceptance
                bool step2Ok = checkInOk && updateProfileOk && appServiceAddOk1 && getIdentityInfoOk1 && appServiceAddOk2 && getIdentityInfoOk2 && appServiceRemoveOk3 &&
                               getIdentityInfoOk3 && appServiceRemoveOk4 && getIdentityInfoOk4 && appServiceAddOk5 && getIdentityInfoOk5 && appServiceAddOk6 && appServiceAddOk7 &&
                               getIdentityInfoOk7 && appServiceAddOk8 && getIdentityInfoOk8;


                Passed = step1Ok && step2Ok;

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

            log.Trace("(-):{0}", res);
            return(res);
        }
Пример #11
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 clientPrimary   = new ProtocolClient();
            ProtocolClient clientSecondary = new ProtocolClient();

            try
            {
                MessageBuilder mbPrimary   = clientPrimary.MessageBuilder;
                MessageBuilder mbSecondary = clientSecondary.MessageBuilder;

                // Step 1
                log.Trace("Step 1");

                // Get port list.
                await clientPrimary.ConnectAsync(ServerIp, PrimaryPort, false);

                Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>();
                bool listPortsOk = await clientPrimary.ListServerPorts(rolePorts);

                clientPrimary.CloseConnection();

                // Establish hosting agreement for primary client.
                await clientPrimary.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHostingOk = await clientPrimary.EstablishHostingAsync("Primary");

                clientPrimary.CloseConnection();

                // Check in primary client.
                await clientPrimary.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                bool checkInOk = await clientPrimary.CheckInAsync();

                bool primaryOk = establishHostingOk && checkInOk;

                // Establish hosting agreement for secondary client.
                await clientSecondary.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                establishHostingOk = await clientSecondary.EstablishHostingAsync("Primary");

                clientSecondary.CloseConnection();

                // Check in secondary client.
                await clientSecondary.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                checkInOk = await clientSecondary.CheckInAsync();

                bool secondaryOk = establishHostingOk && checkInOk;

                // Create card issuers.
                CardIssuers = new List <ProtocolClient>();
                for (int i = 0; i < IssuerCount; i++)
                {
                    ProtocolClient profileClient = new ProtocolClient();
                    CardIssuers.Add(profileClient);
                }


                // Step 1 Acceptance
                bool step1Ok = listPortsOk && primaryOk && secondaryOk;

                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



                // Step 2
                log.Trace("Step 2");

                SignedCards      = new List <SignedRelationshipCard>();
                CardApplications = new List <CardApplicationInformation>();

                // Just to make it easy to follow the test specification.
                ProtocolClient Identity1 = CardIssuers[0];
                ProtocolClient Identity2 = CardIssuers[1];
                ProtocolClient Identity3 = CardIssuers[2];
                ProtocolClient Identity4 = CardIssuers[3];
                ProtocolClient Identity5 = CardIssuers[4];

                log.Trace("Identity1 ID: {0}", Crypto.ToHex(Identity1.GetIdentityId()));
                log.Trace("Identity2 ID: {0}", Crypto.ToHex(Identity2.GetIdentityId()));
                log.Trace("Identity3 ID: {0}", Crypto.ToHex(Identity3.GetIdentityId()));
                log.Trace("Identity4 ID: {0}", Crypto.ToHex(Identity4.GetIdentityId()));
                log.Trace("Identity5 ID: {0}", Crypto.ToHex(Identity5.GetIdentityId()));


                byte[]   primaryPubKey            = clientPrimary.GetIdentityKeys().PublicKey;
                string   type                     = "Card Type A";
                DateTime validFrom                = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                DateTime validTo                  = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                SignedRelationshipCard signedCard = Identity1.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                SignedCards.Add(signedCard);

                byte[] applicationId = new byte[] { 1 };
                CardApplicationInformation cardApplication = clientPrimary.CreateRelationshipCardApplication(applicationId, signedCard);
                CardApplications.Add(cardApplication);

                Message requestMessage = mbPrimary.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await clientPrimary.SendMessageAsync(requestMessage);

                Message responseMessage = await clientPrimary.ReceiveMessageAsync();

                bool idOk     = responseMessage.Id == requestMessage.Id;
                bool statusOk = responseMessage.Response.Status == Status.Ok;

                bool req1Ok = idOk && statusOk;


                type       = "Card Type A";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(1479220557000);
                signedCard = Identity1.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                SignedCards.Add(signedCard);

                applicationId   = new byte[] { 2 };
                cardApplication = clientPrimary.CreateRelationshipCardApplication(applicationId, signedCard);
                CardApplications.Add(cardApplication);

                requestMessage = mbPrimary.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool req2Ok = idOk && statusOk;


                type       = "Card Type A";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = Identity2.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                SignedCards.Add(signedCard);

                applicationId   = new byte[] { 3 };
                cardApplication = clientPrimary.CreateRelationshipCardApplication(applicationId, signedCard);
                CardApplications.Add(cardApplication);

                requestMessage = mbPrimary.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool req3Ok = idOk && statusOk;


                type       = "Card Type A";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(2479220555000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = Identity2.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                SignedCards.Add(signedCard);

                applicationId   = new byte[] { 4 };
                cardApplication = clientPrimary.CreateRelationshipCardApplication(applicationId, signedCard);
                CardApplications.Add(cardApplication);

                requestMessage = mbPrimary.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool req4Ok = idOk && statusOk;


                type       = "Card Type B";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = Identity3.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                SignedCards.Add(signedCard);

                applicationId   = new byte[] { 5 };
                cardApplication = clientPrimary.CreateRelationshipCardApplication(applicationId, signedCard);
                CardApplications.Add(cardApplication);

                requestMessage = mbPrimary.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool req5Ok = idOk && statusOk;


                type       = "Card Type B";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = Identity4.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                SignedCards.Add(signedCard);

                applicationId   = new byte[] { 6 };
                cardApplication = clientPrimary.CreateRelationshipCardApplication(applicationId, signedCard);
                CardApplications.Add(cardApplication);

                requestMessage = mbPrimary.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool req6Ok = idOk && statusOk;


                type       = "Card Type C";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = Identity4.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                SignedCards.Add(signedCard);

                applicationId   = new byte[] { 7 };
                cardApplication = clientPrimary.CreateRelationshipCardApplication(applicationId, signedCard);
                CardApplications.Add(cardApplication);

                requestMessage = mbPrimary.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool req7Ok = idOk && statusOk;


                type       = "Card Type C";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = Identity4.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                SignedCards.Add(signedCard);

                applicationId   = new byte[] { 8 };
                cardApplication = clientPrimary.CreateRelationshipCardApplication(applicationId, signedCard);
                CardApplications.Add(cardApplication);

                requestMessage = mbPrimary.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool req8Ok = idOk && statusOk;


                type       = "Other";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = Identity5.IssueRelationshipCard(primaryPubKey, type, validFrom, validTo);
                SignedCards.Add(signedCard);

                applicationId   = new byte[] { 9 };
                cardApplication = clientPrimary.CreateRelationshipCardApplication(applicationId, signedCard);
                CardApplications.Add(cardApplication);

                requestMessage = mbPrimary.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool req9Ok = idOk && statusOk;


                // Step 2 Acceptance
                bool step2Ok = req1Ok && req2Ok && req3Ok && req4Ok && req5Ok && req6Ok && req7Ok && req8Ok && req9Ok;

                log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED");


                // Step 3
                log.Trace("Step 3");

                byte[] secondaryPubKey = clientSecondary.GetIdentityKeys().PublicKey;
                type       = "Card Type A";
                validFrom  = ProtocolHelper.UnixTimestampMsToDateTime(1479220556000);
                validTo    = ProtocolHelper.UnixTimestampMsToDateTime(2479220556000);
                signedCard = Identity1.IssueRelationshipCard(secondaryPubKey, type, validFrom, validTo);
                SignedCards.Add(signedCard);

                applicationId   = new byte[] { 1 };
                cardApplication = clientSecondary.CreateRelationshipCardApplication(applicationId, signedCard);
                CardApplications.Add(cardApplication);

                requestMessage = mbSecondary.CreateAddRelatedIdentityRequest(cardApplication, signedCard);
                await clientSecondary.SendMessageAsync(requestMessage);

                responseMessage = await clientSecondary.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool req10Ok = idOk && statusOk;


                // Step 3 Acceptance
                bool step3Ok = req10Ok;

                log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED");


                // Step 4
                log.Trace("Step 4");

                byte[] primaryClientId = clientPrimary.GetIdentityId();
                requestMessage = mbSecondary.CreateGetIdentityRelationshipsInformationRequest(primaryClientId, true, null, null);
                await clientSecondary.SendMessageAsync(requestMessage);

                responseMessage = await clientSecondary.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;
                SemVer receivedVersion = new SemVer(responseMessage.Response.SingleResponse.Version);
                bool   versionOk       = receivedVersion.Equals(SemVer.V100);

                HashSet <int> numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                };
                bool relationshipsOk = CheckRelationships(numberList, responseMessage.Response.SingleResponse.GetIdentityRelationshipsInformation.Relationships);

                req1Ok = idOk && statusOk && versionOk && relationshipsOk;


                requestMessage = mbSecondary.CreateGetIdentityRelationshipsInformationRequest(primaryClientId, false, null, null);
                await clientSecondary.SendMessageAsync(requestMessage);

                responseMessage = await clientSecondary.ReceiveMessageAsync();

                idOk            = responseMessage.Id == requestMessage.Id;
                statusOk        = responseMessage.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                numberList = new HashSet <int>()
                {
                    1, 3, 5, 6, 7, 8, 9
                };
                relationshipsOk = CheckRelationships(numberList, responseMessage.Response.SingleResponse.GetIdentityRelationshipsInformation.Relationships);

                req2Ok = idOk && statusOk && versionOk && relationshipsOk;


                requestMessage = mbSecondary.CreateGetIdentityRelationshipsInformationRequest(primaryClientId, true, "*", null);
                await clientSecondary.SendMessageAsync(requestMessage);

                responseMessage = await clientSecondary.ReceiveMessageAsync();

                idOk            = responseMessage.Id == requestMessage.Id;
                statusOk        = responseMessage.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                };
                relationshipsOk = CheckRelationships(numberList, responseMessage.Response.SingleResponse.GetIdentityRelationshipsInformation.Relationships);

                req3Ok = idOk && statusOk && versionOk && relationshipsOk;


                requestMessage = mbSecondary.CreateGetIdentityRelationshipsInformationRequest(primaryClientId, true, "**", null);
                await clientSecondary.SendMessageAsync(requestMessage);

                responseMessage = await clientSecondary.ReceiveMessageAsync();

                idOk            = responseMessage.Id == requestMessage.Id;
                statusOk        = responseMessage.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                };
                relationshipsOk = CheckRelationships(numberList, responseMessage.Response.SingleResponse.GetIdentityRelationshipsInformation.Relationships);

                req4Ok = idOk && statusOk && versionOk && relationshipsOk;


                requestMessage = mbSecondary.CreateGetIdentityRelationshipsInformationRequest(primaryClientId, true, "Card*", null);
                await clientSecondary.SendMessageAsync(requestMessage);

                responseMessage = await clientSecondary.ReceiveMessageAsync();

                idOk            = responseMessage.Id == requestMessage.Id;
                statusOk        = responseMessage.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7, 8
                };
                relationshipsOk = CheckRelationships(numberList, responseMessage.Response.SingleResponse.GetIdentityRelationshipsInformation.Relationships);

                req5Ok = idOk && statusOk && versionOk && relationshipsOk;


                requestMessage = mbSecondary.CreateGetIdentityRelationshipsInformationRequest(primaryClientId, true, "*Type A", null);
                await clientSecondary.SendMessageAsync(requestMessage);

                responseMessage = await clientSecondary.ReceiveMessageAsync();

                idOk            = responseMessage.Id == requestMessage.Id;
                statusOk        = responseMessage.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                numberList = new HashSet <int>()
                {
                    1, 2, 3, 4
                };
                relationshipsOk = CheckRelationships(numberList, responseMessage.Response.SingleResponse.GetIdentityRelationshipsInformation.Relationships);

                req6Ok = idOk && statusOk && versionOk && relationshipsOk;


                requestMessage = mbSecondary.CreateGetIdentityRelationshipsInformationRequest(primaryClientId, true, "*Type *", null);
                await clientSecondary.SendMessageAsync(requestMessage);

                responseMessage = await clientSecondary.ReceiveMessageAsync();

                idOk            = responseMessage.Id == requestMessage.Id;
                statusOk        = responseMessage.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                numberList = new HashSet <int>()
                {
                    1, 2, 3, 4, 5, 6, 7, 8
                };
                relationshipsOk = CheckRelationships(numberList, responseMessage.Response.SingleResponse.GetIdentityRelationshipsInformation.Relationships);

                req7Ok = idOk && statusOk && versionOk && relationshipsOk;


                requestMessage = mbSecondary.CreateGetIdentityRelationshipsInformationRequest(primaryClientId, true, null, Identity1.GetIdentityId());
                await clientSecondary.SendMessageAsync(requestMessage);

                responseMessage = await clientSecondary.ReceiveMessageAsync();

                idOk            = responseMessage.Id == requestMessage.Id;
                statusOk        = responseMessage.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                numberList = new HashSet <int>()
                {
                    1, 2
                };
                relationshipsOk = CheckRelationships(numberList, responseMessage.Response.SingleResponse.GetIdentityRelationshipsInformation.Relationships);

                req8Ok = idOk && statusOk && versionOk && relationshipsOk;


                requestMessage = mbSecondary.CreateGetIdentityRelationshipsInformationRequest(primaryClientId, true, "*C", Identity4.GetIdentityId());
                await clientSecondary.SendMessageAsync(requestMessage);

                responseMessage = await clientSecondary.ReceiveMessageAsync();

                idOk            = responseMessage.Id == requestMessage.Id;
                statusOk        = responseMessage.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                numberList = new HashSet <int>()
                {
                    7, 8
                };
                relationshipsOk = CheckRelationships(numberList, responseMessage.Response.SingleResponse.GetIdentityRelationshipsInformation.Relationships);

                req9Ok = idOk && statusOk && versionOk && relationshipsOk;


                // Step 4 Acceptance
                bool step4Ok = req1Ok && req2Ok && req3Ok && req4Ok && req5Ok && req6Ok && req7Ok && req8Ok && req9Ok;

                log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED");



                // Step 5
                log.Trace("Step 5");

                applicationId  = new byte[] { 2 };
                requestMessage = mbPrimary.CreateRemoveRelatedIdentityRequest(applicationId);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool removeRelation1Ok = idOk && statusOk;

                applicationId  = new byte[] { 4 };
                requestMessage = mbPrimary.CreateRemoveRelatedIdentityRequest(applicationId);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

                idOk     = responseMessage.Id == requestMessage.Id;
                statusOk = responseMessage.Response.Status == Status.Ok;

                bool removeRelation2Ok = idOk && statusOk;



                requestMessage = mbPrimary.CreateGetIdentityRelationshipsInformationRequest(primaryClientId, true, "*Type a*", null);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

                idOk            = responseMessage.Id == requestMessage.Id;
                statusOk        = responseMessage.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                numberList = new HashSet <int>()
                {
                    1, 3
                };
                relationshipsOk = CheckRelationships(numberList, responseMessage.Response.SingleResponse.GetIdentityRelationshipsInformation.Relationships);

                req1Ok = idOk && statusOk && versionOk && relationshipsOk;



                byte[] partId = new byte[10];
                Array.Copy(primaryClientId, partId, partId.Length);
                requestMessage = mbPrimary.CreateGetIdentityRelationshipsInformationRequest(partId, true, "*Type a*", null);
                await clientPrimary.SendMessageAsync(requestMessage);

                responseMessage = await clientPrimary.ReceiveMessageAsync();

                idOk            = responseMessage.Id == requestMessage.Id;
                statusOk        = responseMessage.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessage.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                relationshipsOk = responseMessage.Response.SingleResponse.GetIdentityRelationshipsInformation.Relationships.Count == 0;

                req1Ok = idOk && statusOk && versionOk && relationshipsOk;



                // Step 5 Acceptance
                bool step5Ok = removeRelation1Ok && removeRelation2Ok && req1Ok && req2Ok;

                log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED");


                Passed = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok;

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

            if (CardIssuers != null)
            {
                for (int i = 0; i < IssuerCount; i++)
                {
                    if (CardIssuers[i] != null)
                    {
                        CardIssuers[i].Dispose();
                    }
                }
            }


            log.Trace("(-):{0}", res);
            return(res);
        }
Пример #12
0
        /// <summary>
        /// Checks whether AddRelatedIdentityRequest request is valid.
        /// </summary>
        /// <param name="Client">Client that sent the request.</param>
        /// <param name="AddRelatedIdentityRequest">Client's request message to validate.</param>
        /// <param name="MessageBuilder">Client's network message builder.</param>
        /// <param name="RequestMessage">Full request message from client.</param>
        /// <param name="ErrorResponse">If the function fails, this is filled with error response message that is ready to be sent to the client.</param>
        /// <returns>true if the profile update request can be applied, false otherwise.</returns>
        public static bool ValidateAddRelatedIdentityRequest(IncomingClient Client, AddRelatedIdentityRequest AddRelatedIdentityRequest, PsMessageBuilder MessageBuilder, PsProtocolMessage RequestMessage, out PsProtocolMessage ErrorResponse)
        {
            log.Trace("()");

            bool res = false;

            ErrorResponse = null;
            string details = null;

            if (AddRelatedIdentityRequest == null)
            {
                AddRelatedIdentityRequest = new AddRelatedIdentityRequest();
            }
            if (AddRelatedIdentityRequest.CardApplication == null)
            {
                AddRelatedIdentityRequest.CardApplication = new CardApplicationInformation();
            }
            if (AddRelatedIdentityRequest.SignedCard == null)
            {
                AddRelatedIdentityRequest.SignedCard = new SignedRelationshipCard();
            }
            if (AddRelatedIdentityRequest.SignedCard.Card == null)
            {
                AddRelatedIdentityRequest.SignedCard.Card = new RelationshipCard();
            }

            CardApplicationInformation cardApplication = AddRelatedIdentityRequest.CardApplication;
            SignedRelationshipCard     signedCard      = AddRelatedIdentityRequest.SignedCard;
            RelationshipCard           card            = signedCard.Card;

            byte[] applicationId = cardApplication.ApplicationId.ToByteArray();
            byte[] cardId        = card.CardId.ToByteArray();

            if ((applicationId.Length == 0) || (applicationId.Length > RelatedIdentity.CardIdentifierLength))
            {
                log.Debug("Card application ID is invalid.");
                details = "cardApplication.applicationId";
            }

            if (details == null)
            {
                byte[] appCardId = cardApplication.CardId.ToByteArray();
                if (!ByteArrayComparer.Equals(cardId, appCardId))
                {
                    log.Debug("Card IDs in application card and relationship card do not match.");
                    details = "cardApplication.cardId";
                }
            }

            if (details == null)
            {
                if (card.ValidFrom > card.ValidTo)
                {
                    log.Debug("Card validFrom field is greater than validTo field.");
                    details = "signedCard.card.validFrom";
                }
                else
                {
                    DateTime?cardValidFrom = ProtocolHelper.UnixTimestampMsToDateTime(card.ValidFrom);
                    DateTime?cardValidTo   = ProtocolHelper.UnixTimestampMsToDateTime(card.ValidTo);
                    if (cardValidFrom == null)
                    {
                        log.Debug("Card validFrom value '{0}' is not a valid timestamp.", card.ValidFrom);
                        details = "signedCard.card.validFrom";
                    }
                    else if (cardValidTo == null)
                    {
                        log.Debug("Card validTo value '{0}' is not a valid timestamp.", card.ValidTo);
                        details = "signedCard.card.validTo";
                    }
                }
            }

            if (details == null)
            {
                byte[] issuerPublicKey = card.IssuerPublicKey.ToByteArray();
                bool   pubKeyValid     = (0 < issuerPublicKey.Length) && (issuerPublicKey.Length <= ProtocolHelper.MaxPublicKeyLengthBytes);
                if (!pubKeyValid)
                {
                    log.Debug("Issuer public key has invalid length {0} bytes.", issuerPublicKey.Length);
                    details = "signedCard.card.issuerPublicKey";
                }
            }

            if (details == null)
            {
                byte[] recipientPublicKey = card.RecipientPublicKey.ToByteArray();
                if (!ByteArrayComparer.Equals(recipientPublicKey, Client.PublicKey))
                {
                    log.Debug("Caller is not recipient of the card.");
                    details = "signedCard.card.recipientPublicKey";
                }
            }

            if (details == null)
            {
                if (!Client.MessageBuilder.VerifySignedConversationRequestBodyPart(RequestMessage, cardApplication.ToByteArray(), Client.PublicKey))
                {
                    log.Debug("Caller is not recipient of the card.");
                    ErrorResponse = Client.MessageBuilder.CreateErrorInvalidSignatureResponse(RequestMessage);
                    details       = "";
                }
            }

            if (details == null)
            {
                SemVer cardVersion = new SemVer(card.Version);
                if (!cardVersion.Equals(SemVer.V100))
                {
                    log.Debug("Card version is invalid or not supported.");
                    details = "signedCard.card.version";
                }
            }

            if (details == null)
            {
                if (Encoding.UTF8.GetByteCount(card.Type) > PsMessageBuilder.MaxRelationshipCardTypeLengthBytes)
                {
                    log.Debug("Card type is too long.");
                    details = "signedCard.card.type";
                }
            }

            if (details == null)
            {
                RelationshipCard emptyIdCard = new RelationshipCard()
                {
                    CardId             = ProtocolHelper.ByteArrayToByteString(new byte[RelatedIdentity.CardIdentifierLength]),
                    Version            = card.Version,
                    IssuerPublicKey    = card.IssuerPublicKey,
                    RecipientPublicKey = card.RecipientPublicKey,
                    Type      = card.Type,
                    ValidFrom = card.ValidFrom,
                    ValidTo   = card.ValidTo
                };

                byte[] hash = Crypto.Sha256(emptyIdCard.ToByteArray());
                if (!ByteArrayComparer.Equals(hash, cardId))
                {
                    log.Debug("Card ID '{0}' does not match its hash '{1}'.", cardId.ToHex(64), hash.ToHex());
                    details = "signedCard.card.cardId";
                }
            }

            if (details == null)
            {
                byte[] issuerSignature = signedCard.IssuerSignature.ToByteArray();
                byte[] issuerPublicKey = card.IssuerPublicKey.ToByteArray();
                if (!Ed25519.Verify(issuerSignature, cardId, issuerPublicKey))
                {
                    log.Debug("Issuer signature is invalid.");
                    details = "signedCard.issuerSignature";
                }
            }

            if (details == null)
            {
                res = true;
            }
            else
            {
                if (ErrorResponse == null)
                {
                    ErrorResponse = MessageBuilder.CreateErrorInvalidValueResponse(RequestMessage, details);
                }
            }

            log.Trace("(-):{0}", res);
            return(res);
        }
Пример #13
0
        /// <summary>
        /// Checks whether a profile information is valid.
        /// </summary>
        /// <param name="Profile">Profile information to check.</param>
        /// <param name="IdentityPublicKey">Public key of the profile's identity.</param>
        /// <param name="MessageBuilder">Client's network message builder.</param>
        /// <param name="RequestMessage">Full request message from client.</param>
        /// <param name="ErrorPrefix">Prefix to add to the validation error details.</param>
        /// <param name="ErrorResponse">If the function fails, this is filled with error response message that is ready to be sent to the client.</param>
        /// <returns>true if the signed profile information is valid, false otherwise.</returns>
        public static bool ValidateProfileInformation(ProfileInformation Profile, byte[] IdentityPublicKey, PsMessageBuilder MessageBuilder, PsProtocolMessage RequestMessage, string ErrorPrefix, out PsProtocolMessage ErrorResponse)
        {
            log.Trace("()");

            bool res = false;

            ErrorResponse = null;
            string details = null;

            if (Profile == null)
            {
                Profile = new ProfileInformation();
            }

            SemVer version = new SemVer(Profile.Version);

            // Currently only supported version is 1.0.0.
            if (!version.Equals(SemVer.V100))
            {
                log.Debug("Unsupported version '{0}'.", version);
                details = "version";
            }


            if (details == null)
            {
                byte[] pubKey      = Profile.PublicKey.ToByteArray();
                bool   pubKeyValid = (0 < pubKey.Length) && (pubKey.Length <= ProtocolHelper.MaxPublicKeyLengthBytes) && ByteArrayComparer.Equals(IdentityPublicKey, pubKey);
                if (!pubKeyValid)
                {
                    log.Debug("Invalid public key '{0}' does not match identity public key '{1}'.", pubKey.ToHex(), IdentityPublicKey.ToHex());
                    details = "publicKey";
                }
            }

            if (details == null)
            {
                int  typeSize  = Encoding.UTF8.GetByteCount(Profile.Type);
                bool typeValid = (0 < typeSize) && (typeSize <= IdentityBase.MaxProfileTypeLengthBytes);
                if (!typeValid)
                {
                    log.Debug("Invalid type size in bytes {0}.", typeSize);
                    details = "type";
                }
            }

            if (details == null)
            {
                int  nameSize  = Encoding.UTF8.GetByteCount(Profile.Name);
                bool nameValid = (0 < nameSize) && (nameSize <= IdentityBase.MaxProfileNameLengthBytes);
                if (!nameValid)
                {
                    log.Debug("Invalid name size in bytes {0}.", nameSize);
                    details = "name";
                }
            }

            if (details == null)
            {
                GpsLocation locLat = new GpsLocation(Profile.Latitude, 0);
                if (!locLat.IsValid())
                {
                    log.Debug("Invalid latitude {0}.", Profile.Latitude);
                    details = "latitude";
                }
            }

            if (details == null)
            {
                GpsLocation locLon = new GpsLocation(0, Profile.Longitude);
                if (!locLon.IsValid())
                {
                    log.Debug("Invalid longitude {0}.", Profile.Longitude);
                    details = "longitude";
                }
            }

            if (details == null)
            {
                int  extraDataSize  = Encoding.UTF8.GetByteCount(Profile.ExtraData);
                bool extraDataValid = extraDataSize <= IdentityBase.MaxProfileExtraDataLengthBytes;
                if (!extraDataValid)
                {
                    log.Debug("Invalid extraData size in bytes {0}.", extraDataSize);
                    details = "extraData";
                }
            }

            if (details == null)
            {
                bool profileImageHashValid = (Profile.ProfileImageHash.Length == 0) || (Profile.ProfileImageHash.Length == ProtocolHelper.HashLengthBytes);
                if (!profileImageHashValid)
                {
                    log.Debug("Invalid profile image hash size {0} bytes.", Profile.ProfileImageHash.Length);
                    details = "profileImageHash";
                }
            }

            if (details == null)
            {
                bool thumbnailImageHashValid = (Profile.ThumbnailImageHash.Length == 0) || (Profile.ThumbnailImageHash.Length == ProtocolHelper.HashLengthBytes);
                if (!thumbnailImageHashValid)
                {
                    log.Debug("Invalid thumbnail image hash size {0} bytes.", Profile.ThumbnailImageHash.Length);
                    details = "thumbnailImageHash";
                }
            }


            if (details == null)
            {
                res = true;
            }
            else
            {
                ErrorResponse = MessageBuilder.CreateErrorInvalidValueResponse(RequestMessage, ErrorPrefix + details);
            }

            log.Trace("(-):{0}", res);
            return(res);
        }
        /// <summary>
        /// Compares this activity to other activity and returns list of changed properties.
        /// </summary>
        /// <param name="Other">Other activity to compare to.</param>
        /// <returns>Bit mask information about which properties are different.</returns>
        public ActivityChange CompareChangeTo(ActivityBase Other)
        {
            ActivityChange res = ActivityChange.None;

            SemVer thisVersion  = new SemVer(this.Version);
            SemVer otherVersion = new SemVer(Other.Version);

            if (!thisVersion.Equals(otherVersion))
            {
                res |= ActivityChange.Version;
            }

            if (this.ActivityId != Other.ActivityId)
            {
                res |= ActivityChange.ActivityId;
            }

            if (!ByteArrayComparer.Equals(this.OwnerIdentityId, Other.OwnerIdentityId))
            {
                res |= ActivityChange.OwnerIdentityId;
            }

            if (!ByteArrayComparer.Equals(this.OwnerPublicKey, Other.OwnerPublicKey))
            {
                res |= ActivityChange.OwnerPublicKey;
            }

            if (!ByteArrayComparer.Equals(this.OwnerProfileServerId, Other.OwnerProfileServerId))
            {
                res |= ActivityChange.OwnerProfileServerId;
            }

            if (!ByteArrayComparer.Equals(this.OwnerProfileServerIpAddress, Other.OwnerProfileServerIpAddress))
            {
                res |= ActivityChange.OwnerProfileServerIpAddress;
            }

            if (this.OwnerProfileServerPrimaryPort != Other.OwnerProfileServerPrimaryPort)
            {
                res |= ActivityChange.OwnerProfileServerPrimaryPort;
            }

            if (this.Type != Other.Type)
            {
                res |= ActivityChange.Type;
            }

            if (this.LocationLatitude != Other.LocationLatitude)
            {
                res |= ActivityChange.LocationLatitude;
            }

            if (this.LocationLongitude != Other.LocationLongitude)
            {
                res |= ActivityChange.LocationLongitude;
            }

            if (this.PrecisionRadius != Other.PrecisionRadius)
            {
                res |= ActivityChange.PrecisionRadius;
            }

            if (this.StartTime != Other.StartTime)
            {
                res |= ActivityChange.StartTime;
            }

            if (this.ExpirationTime != Other.ExpirationTime)
            {
                res |= ActivityChange.ExpirationTime;
            }

            if (this.ExtraData != Other.ExtraData)
            {
                res |= ActivityChange.ExtraData;
            }

            return(res);
        }
Пример #15
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 clientCallee           = new ProtocolClient();
            ProtocolClient clientCalleeAppService = new ProtocolClient(0, SemVer.V100, clientCallee.GetIdentityKeys());

            ProtocolClient clientCaller1           = new ProtocolClient();
            ProtocolClient clientCaller1AppService = new ProtocolClient(0, SemVer.V100, clientCaller1.GetIdentityKeys());

            ProtocolClient clientCaller2           = new ProtocolClient();
            ProtocolClient clientCaller2AppService = new ProtocolClient(0, SemVer.V100, clientCaller2.GetIdentityKeys());

            try
            {
                MessageBuilder mbCallee           = clientCallee.MessageBuilder;
                MessageBuilder mbCalleeAppService = clientCalleeAppService.MessageBuilder;

                MessageBuilder mbCaller1           = clientCaller1.MessageBuilder;
                MessageBuilder mbCaller1AppService = clientCaller1AppService.MessageBuilder;

                MessageBuilder mbCaller2           = clientCaller2.MessageBuilder;
                MessageBuilder mbCaller2AppService = clientCaller2AppService.MessageBuilder;


                // Step 1
                log.Trace("Step 1");

                byte[] pubKeyCallee     = clientCallee.GetIdentityKeys().PublicKey;
                byte[] identityIdCallee = clientCallee.GetIdentityId();

                byte[] pubKeyCaller1     = clientCaller1.GetIdentityKeys().PublicKey;
                byte[] identityIdCaller1 = clientCaller1.GetIdentityId();

                byte[] pubKeyCaller2     = clientCaller2.GetIdentityKeys().PublicKey;
                byte[] identityIdCaller2 = clientCaller2.GetIdentityId();

                // Get port list.

                await clientCallee.ConnectAsync(ServerIp, PrimaryPort, false);

                Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>();
                bool listPortsOk = await clientCallee.ListServerPorts(rolePorts);

                clientCallee.CloseConnection();


                // Establish hosting agreement for identity 1.
                await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHostingOk = await clientCallee.EstablishHostingAsync();

                clientCallee.CloseConnection();


                // Check-in and initialize the profile of identity 1.

                await clientCallee.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                bool checkInOk = await clientCallee.CheckInAsync();

                bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, new GpsLocation(0, 0), null);


                // Add application service to the current session.
                string serviceName     = "Test Service";
                bool   addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName });


                // Step 1 Acceptance
                bool step1Ok = listPortsOk && establishHostingOk && checkInOk && initializeProfileOk && addAppServiceOk;

                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



                // Step 2
                log.Trace("Step 2");
                await clientCaller1.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool verifyIdentityOk1 = await clientCaller1.VerifyIdentityAsync();

                Message requestMessage       = mbCaller1.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName);
                uint    initMessageCaller1Id = requestMessage.Id;
                await clientCaller1.SendMessageAsync(requestMessage);


                await clientCaller2.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool verifyIdentityOk2 = await clientCaller2.VerifyIdentityAsync();

                requestMessage = mbCaller2.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName);
                uint initMessageCaller2Id = requestMessage.Id;
                await clientCaller2.SendMessageAsync(requestMessage);



                // Step 2 Acceptance
                bool step2Ok = verifyIdentityOk1 && verifyIdentityOk2;

                log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED");



                // Step 3
                log.Trace("Step 3");
                Message serverRequestMessage = await clientCallee.ReceiveMessageAsync();

                // What we received now can actually be either notification about caller1 or caller2, we do not know.
                // So we have to check, which one is it before we proceed.
                byte[] receivedPubKey = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray();
                bool   isCaller1      = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller1) == 0;
                bool   isCaller2      = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller2) == 0;
                bool   pubKeyOk       = isCaller1 || isCaller2;
                bool   serviceNameOk  = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName;

                bool incomingCallNotificationOk1 = pubKeyOk && serviceNameOk;

                byte[] calleeToken1 = null;
                byte[] calleeToken2 = null;
                if (isCaller1)
                {
                    calleeToken1 = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray();
                }
                else
                {
                    calleeToken2 = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray();
                }

                Message serverResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(serverRequestMessage);
                await clientCallee.SendMessageAsync(serverResponseMessage);



                serverRequestMessage = await clientCallee.ReceiveMessageAsync();

                // This time, it has to be the other caller
                receivedPubKey = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray();
                if (isCaller1)
                {
                    pubKeyOk = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller2) == 0;
                }
                else
                {
                    pubKeyOk = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller1) == 0;
                }
                serviceNameOk = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName;

                bool incomingCallNotificationOk2 = pubKeyOk && serviceNameOk;

                if (isCaller1)
                {
                    calleeToken2 = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray();
                }
                else
                {
                    calleeToken1 = serverRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray();
                }

                serverResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(serverRequestMessage);
                await clientCallee.SendMessageAsync(serverResponseMessage);



                // Connect to clAppService and send initialization message.
                await clientCalleeAppService.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken1, null);
                await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee);


                // Step 3 Acceptance
                bool step3Ok = incomingCallNotificationOk1 && incomingCallNotificationOk2;

                log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED");


                // Step 4
                log.Trace("Step 4");
                Message responseMessage = await clientCaller1.ReceiveMessageAsync();

                bool   idOk        = responseMessage.Id == initMessageCaller1Id;
                bool   statusOk    = responseMessage.Response.Status == Status.Ok;
                byte[] callerToken = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray();

                bool callIdentityOk = idOk && statusOk;

                // Connect to clAppService and send initialization message.
                await clientCaller1AppService.ConnectAsync(ServerIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCaller = mbCaller1AppService.CreateApplicationServiceSendMessageRequest(callerToken, null);
                await clientCaller1AppService.SendMessageAsync(requestMessageAppServiceCaller);

                Message responseMessageAppServiceCaller = await clientCaller1AppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id;
                statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok;

                bool initAppServiceMessageOk = idOk && statusOk;


                // Step 4 Acceptance
                bool step4Ok = callIdentityOk && initAppServiceMessageOk;

                log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED");



                // Step 5
                log.Trace("Step 5");
                Message responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id;
                statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok;

                bool typeOk = (responseMessageAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Response) &&
                              (responseMessageAppServiceCallee.Response.ConversationTypeCase == Response.ConversationTypeOneofCase.SingleResponse) &&
                              (responseMessageAppServiceCallee.Response.SingleResponse.ResponseTypeCase == SingleResponse.ResponseTypeOneofCase.ApplicationServiceSendMessage);

                bool appServiceSendOk = idOk && statusOk && typeOk;

                // Step 5 Acceptance
                bool step5Ok = appServiceSendOk;

                log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED");



                // Step 6
                log.Trace("Step 6");
                string caller1Message1 = "Message #1 to callee.";
                byte[] messageBytes    = Encoding.UTF8.GetBytes(caller1Message1);
                requestMessageAppServiceCaller = mbCaller1AppService.CreateApplicationServiceSendMessageRequest(callerToken, messageBytes);
                uint callerMessage1Id = requestMessageAppServiceCaller.Id;
                await clientCaller1AppService.SendMessageAsync(requestMessageAppServiceCaller);


                // Step 6 Acceptance
                bool step6Ok = true;

                log.Trace("Step 6: {0}", step6Ok ? "PASSED" : "FAILED");


                // Step 7
                log.Trace("Step 7");
                // Receive message #1.
                Message serverRequestAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                SemVer receivedVersion = new SemVer(serverRequestAppServiceCallee.Request.SingleRequest.Version);
                bool   versionOk       = receivedVersion.Equals(SemVer.V100);

                typeOk = (serverRequestAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Request) &&
                         (serverRequestAppServiceCallee.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) &&
                         (serverRequestAppServiceCallee.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification);

                string receivedMessage = Encoding.UTF8.GetString(serverRequestAppServiceCallee.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray());
                bool   messageOk       = receivedMessage == caller1Message1;

                bool receiveMessageOk = versionOk && typeOk && messageOk;


                // ACK message #1.
                Message serverResponseAppServiceCallee = mbCalleeAppService.CreateApplicationServiceReceiveMessageNotificationResponse(serverRequestAppServiceCallee);
                await clientCalleeAppService.SendMessageAsync(serverResponseAppServiceCallee);



                // Send second intialization message
                await Task.Delay(3000);

                requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken2, null);
                await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee);

                Message responseAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                idOk     = responseAppServiceCallee.Id == requestMessageAppServiceCallee.Id;
                statusOk = responseAppServiceCallee.Response.Status == Status.ErrorNotFound;

                bool secondInitOk = idOk && statusOk;


                // Step 7 Acceptance
                bool step7Ok = secondInitOk;

                log.Trace("Step 7: {0}", step7Ok ? "PASSED" : "FAILED");


                // Step 8
                log.Trace("Step 8");

                // Receive init message response.
                bool initMessageOk = false;
                bool disconnectOk  = false;
                try
                {
                    Message initMessageResponseAppServiceCaller2 = await clientCaller2AppService.ReceiveMessageAsync();

                    idOk     = initMessageResponseAppServiceCaller2.Id == initMessageCaller2Id;
                    statusOk = initMessageResponseAppServiceCaller2.Response.Status == Status.ErrorNotFound;

                    initMessageOk = idOk && statusOk;
                }
                catch
                {
                    log.Trace("Expected exception occurred.");
                    disconnectOk = true;
                }

                // Step 8 Acceptance
                bool step8Ok = initMessageOk || disconnectOk;

                log.Trace("Step 8: {0}", step8Ok ? "PASSED" : "FAILED");


                // Step 9
                log.Trace("Step 9");

                // Receive ACK message #1.
                responseMessageAppServiceCaller = await clientCaller1AppService.ReceiveMessageAsync();

                idOk            = responseMessageAppServiceCaller.Id == callerMessage1Id;
                statusOk        = responseMessageAppServiceCaller.Response.Status == Status.Ok;
                receivedVersion = new SemVer(responseMessageAppServiceCaller.Response.SingleResponse.Version);
                versionOk       = receivedVersion.Equals(SemVer.V100);

                bool receiveAckOk = idOk && statusOk && versionOk;

                // Step 9 Acceptance
                bool step9Ok = receiveAckOk;

                log.Trace("Step 9: {0}", step9Ok ? "PASSED" : "FAILED");

                Passed = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok && step7Ok && step8Ok && step9Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            clientCallee.Dispose();
            clientCalleeAppService.Dispose();
            clientCaller1.Dispose();
            clientCaller1AppService.Dispose();
            clientCaller2.Dispose();
            clientCaller2AppService.Dispose();

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