Ejemplo n.º 1
0
    def sendFile(self, fileName, fileContents, guid):
        try:
            self.progressIndeterminate()
            selectedPeer = self.peers[guid]
            filePrivateKey = generateDHPrivate()
            filePublicKey = calculateDHPublic(filePrivateKey)
            preSendPublicKey = PublicKey(filePublicKey, self.peers[guid].sharedPassword)
            preSendRequest = PreSendRequest(fileName, preSendPublicKey)
            preSendSocket = self.sendRequestToPeer(guid, REQUEST_TYPE_PRE_SEND, objectToJSON(preSendRequest))
            response = preSendSocket.recv().decode("utf-8")
            if response == RESPONSE_NOT_PAIRED:
                self.pair(guid, continueToSend=(fileName, fileContents, guid))
                return
            elif response == RESPONSE_REJECT:
                self.showMessageBox.emit("File rejected")
                self.progressStop()
                return
        except FileTransferBaseException as e:
            self.showMessageBox.emit(e.message)
            return

        def senderThread():
            try:
                aesKey = calculateDHAES(selectedPeer.publicKey, filePrivateKey)
                sentFile = File(fileName, fileContents, aesKey)
                self.sendRequestToPeer(guid, REQUEST_TYPE_SEND, objectToJSON(sentFile), 5)
                self.progressStop()
            except FileTransferBaseException as e:
                self.showMessageBox.emit(e.message)

        sThread = threading.Thread(target=senderThread)
        sThread.start()
Ejemplo n.º 2
0
 def handlerThread():
     try:
         if not signatureSecret:
             socket.send(RESPONSE_REJECT)
             return
         if not requestData.publicKey.verifySignature(signatureSecret):
             self.showMessageBox.emit("Bad shared password")
             socket.send(RESPONSE_BAD_SIGNATURE)
             return
         myPrivateKey = generateDHPrivate()
         myPublicKey = calculateDHPublic(myPrivateKey)
         publicKey = PublicKey(myPublicKey, signatureSecret)
         self.sendRequestToSocket(socket, REQUEST_TYPE_PUBLICKEY, objectToJSON(publicKey), 5)
         response = socket.recv().decode("utf-8")
         if response != RESPONSE_OK:
             self.showMessageBox.emit(response)
             return
         if request.guid not in self.peers:
             self.peers[request.guid] = Peer(request.guid, requestData.name)
         self.peers[request.guid].myPrivateKey = myPrivateKey
         self.peers[request.guid].publicKey = requestData.publicKey.key
         self.peers[request.guid].sharedPassword = signatureSecret
         self.peers[request.guid].lastKnownIP = socket.address
         self.storePeers()
         self.peersUpdated.emit()
     except FileTransferBaseException as e:
         self.showMessageBox.emit(e.message)
Ejemplo n.º 3
0
 def pairThread():
     try:
         self.progressIndeterminate()
         myPrivateKey = generateDHPrivate()
         myPublicKey = calculateDHPublic(myPrivateKey)
         nonlocal sharedPassword
         if sharedPassword is None:
             self.progressStop()
             return False
         sharedPassword = sharedPassword
         requestPublicKey = PublicKey(myPublicKey, sharedPassword)
         pairingRequest = PairingRequest(self.name, self.guid, requestPublicKey)
         peerSocket = self.sendRequestToPeer(guid, REQUEST_TYPE_PAIR, objectToJSON(pairingRequest))
         response = peerSocket.recv().decode("utf-8")
         if response == RESPONSE_REJECT or response == RESPONSE_BAD_SIGNATURE:
             self.showMessageBox.emit(response)
             return False
         peersKey = JSONToObject(PublicKey, JSONToObject(Request, response).data)
         if not peersKey.verifySignature(sharedPassword):
             self.showMessageBox.emit("Bad shared password")
             peerSocket.send(RESPONSE_BAD_SIGNATURE)
             return False
         peerSocket.setTimeout(5)
         peerSocket.send(RESPONSE_OK)
         self.peers[guid].myPrivateKey = myPrivateKey
         self.peers[guid].publicKey = peersKey.key
         self.peers[guid].sharedPassword = sharedPassword
         self.storePeers()
         self.peersUpdated.emit()
         self.progressStop()
         if continueToSend:
             self.continueSend.emit(*continueToSend)
     except FileTransferBaseException as e:
         self.showMessageBox.emit(e.message)