Пример #1
0
 private async static void requestReceived(TCPSocket sender)
 {
     await uiThreadDispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
     {
         try
         {
             progressIndeterminate();
             sender.ProgressRepport += (x) => { if (ProgressRepport != null) ProgressRepport(x); };
             string requestContents = await sender.Recv();
             progressStop();
             Request receivedRequest = JSONHandling.ParseJSONResponse<Request>(requestContents);
             await requestHandlerMap[receivedRequest.Type](receivedRequest.SenderGuid, receivedRequest.Data, sender);
         }
         catch(OutOfMemoryException)
         {
             DialogBoxes.ShowMessageBox("File too big to fit in memory");
         }
         catch(FileTransferException error)
         {
             DialogBoxes.ShowMessageBox(error.Message);
         }
         catch(Exception error)
         {
             DialogBoxes.ShowMessageBox("Unknown error " + error.Message);
         }
         finally
         {
             progressStop();
             sender.Send(Strings.RESPONSE_REJECT);
         }
     });
 }
Пример #2
0
        private static async void deviceDiscovered(TCPSocket sender)
        {
            try
            {
                string ip = sender.GetIP();
                string receivedString = await sender.Recv();
                if (receivedString.IndexOf(":") == -1 || receivedString.IndexOf(":") == receivedString.Length-1) return;
                string guid = receivedString.Substring(0, receivedString.IndexOf(":"));
                if (guid == (await GuidHandling.GetMyGuid())) return;
                string name = receivedString.Substring(receivedString.IndexOf(":") + 1);
                DeviceDiscovered(ip, guid, name);
            }
            catch(Exception)
            {

            }
        }
Пример #3
0
        private async static Task pairRequestReceived(string peer, string data, TCPSocket socket)
        {
            progressIndeterminate();
            var request = JSONHandling.ParseJSONResponse<PairingRequest>(data);
            if(request.Guid!=peer) 
            {
                progressStop();
                await socket.Send(Strings.RESPONSE_REJECT);
                return;
            }
            string signatureSecret = await DialogBoxes.AskForInput("Pairing request", "Please enter the shared password");
            if (signatureSecret == null)
            {
                progressStop();
                await socket.Send(Strings.RESPONSE_REJECT);
                return;
            }

            if(!request.PublicKey.VerifySignature(signatureSecret))
            {
                progressStop();
                await socket.Send(Strings.RESPONSE_BAD_SIGNATURE);
                await DialogBoxes.ShowMessageBox("Shared password incorrect");
                return;
            }
            string myPrivateKey = DiffieHellman.generate_DH_Private();
            string myPublicKey = DiffieHellman.calculate_DH_Public(myPrivateKey);
            PublicKey returnedKey = new PublicKey(myPublicKey, signatureSecret);

            await sendRequestToSocket(socket, Strings.REQYEST_TYPE_PUBLICKEY, JSONHandling.SerializeObject(returnedKey));
            string response = await socket.Recv();
            progressStop();
            if(response!=Strings.RESPONSE_OK)
            {
                await DialogBoxes.ShowMessageBox(response);
                return;
            }

            Peer newPeer = new Peer(request.Guid, request.Name);
            newPeer.LastKnownIP = socket.GetIP();
            newPeer.MyPrivateKey = myPrivateKey;
            newPeer.PublicKey = request.PublicKey.Key;
            newPeer.SharedPassword = signatureSecret;
            addPeer(newPeer);
            await StorePeers();
            RefreshPeerMap();
        }