Beispiel #1
0
    def handlePairRequest(self, socket, request):
        requestData = JSONToObject(PairingRequest, request.data)
        signatureSecret = askForInput(self.parent,
                                      "Pairing request from " + requestData.name + ". Enter shared password:"******"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)

        hThread = Thread(target=handlerThread)
        hThread.start()
Beispiel #2
0
    def pair(self, guid, continueToSend=None):
        sharedPassword = askForInput(self.parent, "Enter shared password")

        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)

        pairerThread = Thread(target=pairThread)
        pairerThread.start()