Ejemplo n.º 1
0
        private static void FinishDeviceNegotiation(InformationContext iCtx, INegotiationProtocolMember protocolParty, string remainingDetails)
        {
            var result = CreateDeviceMembership.Execute(new CreateDeviceMembershipParameters
            {
                Owner = iCtx.Owner,
                ActiveSymmetricAESKey = protocolParty.NegotiationResults[0],
                DeviceDescription     = remainingDetails
            });

            CreateAndSendEmailValidationForDeviceJoinConfirmation.Execute(new CreateAndSendEmailValidationForDeviceJoinConfirmationParameters
            {
                DeviceMembership = result.DeviceMembership,
                OwningAccount    = iCtx.Owner as TBAccount,
                OwningGroup      = iCtx.Owner as TBCollaboratingGroup,
            });
        }
Ejemplo n.º 2
0
        public static void EchoClient()
        {
            Console.WriteLine("Starting EKE WSS connection");
            //string hostWithProtocolAndPort = "ws://*****:*****@gmail.com";
            string idParam             = "groupID=4ddf4bef-0f60-41b6-925d-02721e89d637";
            string deviceConnectionUrl = hostWithProtocolAndPort + "/websocket/NegotiateDeviceConnection?" + idParam;

            //socket = new WebSocket("wss://theball.protonit.net/websocket/mytest.k");
            socket            = new WebSocket(deviceConnectionUrl);
            socket.OnOpen    += socket_OnOpen;
            socket.OnClose   += socket_OnClose;
            socket.OnError   += socket_OnError;
            socket.OnMessage += socket_OnMessage;
            TheBallEKE instance = new TheBallEKE();

            instance.InitiateCurrentSymmetricFromSecret("testsecretXYZ33");
            playAlice = false;
            if (playAlice)
            {
                protocolMember = new TheBallEKE.EKEAlice(instance);
            }
            else
            {
                protocolMember = new TheBallEKE.EKEBob(instance);
            }
            protocolMember.SendMessageToOtherParty = bytes => { socket.Send(bytes); };
            watch.Start();
            socket.Connect();
#if native45
            //WebSocket socket = new ClientWebSocket();
            //WebSocket.CreateClientWebSocket()
            ClientWebSocket socket = new ClientWebSocket();
            Uri             uri    = new Uri("ws://localhost:50430/websocket/mytest.k");
            var             cts    = new CancellationTokenSource();
            await socket.ConnectAsync(uri, cts.Token);

            Console.WriteLine(socket.State);

            Task.Factory.StartNew(
                async() =>
            {
                var rcvBytes  = new byte[128];
                var rcvBuffer = new ArraySegment <byte>(rcvBytes);
                while (true)
                {
                    WebSocketReceiveResult rcvResult = await socket.ReceiveAsync(rcvBuffer, cts.Token);
                    byte[] msgBytes = rcvBuffer.Skip(rcvBuffer.Offset).Take(rcvResult.Count).ToArray();
                    string rcvMsg   = Encoding.UTF8.GetString(msgBytes);
                    Console.WriteLine("Received: {0}", rcvMsg);
                }
            }, cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);

            while (true)
            {
                var message = Console.ReadLine();
                if (message == "Bye")
                {
                    cts.Cancel();
                    return;
                }
                byte[] sendBytes  = Encoding.UTF8.GetBytes(message);
                var    sendBuffer = new ArraySegment <byte>(sendBytes);
                await
                socket.SendAsync(sendBuffer, WebSocketMessageType.Text, endOfMessage : true,
                                 cancellationToken : cts.Token);
            }
#endif
        }
Ejemplo n.º 3
0
 private static string FinishDeviceNegotiation(InformationContext iCtx, INegotiationProtocolMember protocolParty, string remainingDetails)
 {
     try
     {
         var result = CreateDeviceMembership.Execute(new CreateDeviceMembershipParameters
             {
                 Owner = iCtx.Owner,
                 ActiveSymmetricAESKey = protocolParty.NegotiationResults[0],
                 DeviceDescription = remainingDetails
             });
         CreateAndSendEmailValidationForDeviceJoinConfirmation.Execute(new CreateAndSendEmailValidationForDeviceJoinConfirmationParameters
             {
                 DeviceMembership = result.DeviceMembership,
                 OwningAccount = iCtx.Owner as TBAccount,
                 OwningGroup = iCtx.Owner as TBCollaboratingGroup,
             });
         return result.DeviceMembership.ID;
     }
     finally
     {
         iCtx.PerformFinalizingActions();
     }
 }
Ejemplo n.º 4
0
        private async static Task HandleDeviceNegotiations(InformationContext iCtx, WebSocketContext wsCtx, WebSocket socket, byte[] binaryMessage, string textMessage)
        {
            bool playBob = false;
            INegotiationProtocolMember protocolParty = null;

            if (binaryMessage != null)
            {
                iCtx.AccessLockedItems(dict =>
                {
                    if (dict.ContainsKey("EKENEGOTIATIONPARTY") == false)
                    {
                        TheBallEKE protocolInstance = new TheBallEKE();
                        protocolInstance.InitiateCurrentSymmetricFromSecret("testsecretXYZ33");
                        if (playBob)
                        {
                            protocolParty = new TheBallEKE.EKEBob(protocolInstance, true);
                        }
                        else
                        {
                            protocolParty = new TheBallEKE.EKEAlice(protocolInstance, true);
                        }
                        dict.Add("EKENEGOTIATIONPARTY", protocolParty);
                    }
                    else
                    {
                        protocolParty = (INegotiationProtocolMember)dict["EKENEGOTIATIONPARTY"];
                    }
                });
                if (protocolParty.SendMessageToOtherPartyAsync == null)
                {
                    protocolParty.SendMessageToOtherPartyAsync = async bytes => { await SendBinaryMessage(socket, bytes); };
                    if (playBob) // if we play bob we put the current message already to the pipeline
                    {
                        protocolParty.LatestMessageFromOtherParty = binaryMessage;
                    }
                }
                else
                {
                    // Alice plays first, so only after the second message we start putting messages from Bob
                    protocolParty.LatestMessageFromOtherParty = binaryMessage;
                }
                while (protocolParty.IsDoneWithProtocol == false && protocolParty.WaitForOtherParty == false)
                {
                    await protocolParty.PerformNextActionAsync();
                }
            }
            else
            {
                iCtx.AccessLockedItems(dict =>
                {
                    if (dict.ContainsKey("EKENEGOTIATIONPARTY"))
                    {
                        protocolParty = (INegotiationProtocolMember)dict["EKENEGOTIATIONPARTY"];
                    }
                });
                if (protocolParty != null && protocolParty.IsDoneWithProtocol) // Perform POST EKE operations
                {
                    iCtx.AccessLockedItems(dict => dict.Remove("EKENEGOTIATIONPARTY"));
                    FinishDeviceNegotiation(iCtx, protocolParty, textMessage);
                }
                //await SendTextMessage(socket, echoString);
            }
        }