[gnome-keysign: 4/65] bluetooth: handle long keys



commit a5b7bf558936b8b17b51c8f29308e5398377d442
Author: RyuzakiKK <aasonykk gmail com>
Date:   Mon Aug 7 16:13:55 2017 +0200

    bluetooth: handle long keys
    
    If a key is long it may be divided in multiple packets. With sendall we
    are sure that the whole key will be sent.

 keysign/bluetoothoffer.py   | 2 +-
 keysign/bluetoothreceive.py | 5 ++++-
 2 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/keysign/bluetoothoffer.py b/keysign/bluetoothoffer.py
index a12a2e4..14316f6 100644
--- a/keysign/bluetoothoffer.py
+++ b/keysign/bluetoothoffer.py
@@ -34,7 +34,7 @@ class BluetoothOffer:
             client_socket, address = yield threads.deferToThread(self.server_socket.accept)
             key_data = get_public_key_data(self.key.fingerprint)
             kd_decoded = key_data.decode('utf-8')
-            yield threads.deferToThread(client_socket.send, kd_decoded)
+            yield threads.deferToThread(client_socket.sendall, kd_decoded)
             log.info("Key has been sent")
             success = True
         except Exception as e:
diff --git a/keysign/bluetoothreceive.py b/keysign/bluetoothreceive.py
index a6fc09b..18e2474 100644
--- a/keysign/bluetoothreceive.py
+++ b/keysign/bluetoothreceive.py
@@ -21,7 +21,10 @@ class BluetoothReceive:
         self.client_socket = BluetoothSocket(RFCOMM)
         try:
             yield threads.deferToThread(self.client_socket.connect, (mac, self.port))
-            message = yield threads.deferToThread(self.client_socket.recv, self.size)
+            message = b""
+            while len(message) < 35 or message[-35:] != b"-----END PGP PUBLIC KEY BLOCK-----\n":
+                part_message = yield threads.deferToThread(self.client_socket.recv, self.size)
+                message += part_message
         except Exception as e:  # TODO better handling
             log.error("An error occurred connecting or receiving: %s" % e)
             key_data = None


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]