[gnome-keysign: 24/65] bluetooth: add hmac requirement also with direct execution



commit e6af4a686f93283ef924fa9e22e7de1198b4d6bb
Author: RyuzakiKK <aasonykk gmail com>
Date:   Sun Aug 20 15:53:19 2017 +0200

    bluetooth: add hmac requirement also with direct execution

 keysign/bluetoothoffer.py   | 7 ++++---
 keysign/bluetoothreceive.py | 7 ++++---
 2 files changed, 8 insertions(+), 6 deletions(-)
---
diff --git a/keysign/bluetoothoffer.py b/keysign/bluetoothoffer.py
index 9323814..8421e3d 100644
--- a/keysign/bluetoothoffer.py
+++ b/keysign/bluetoothoffer.py
@@ -22,8 +22,7 @@ if __name__ == "__main__" and __package__ is None:
     __package__ = str('keysign')
 
 from .gpgmh import get_public_key_data, get_usable_keys
-from .util import get_local_bt_address
-
+from .util import get_local_bt_address, mac_generate
 
 log = logging.getLogger(__name__)
 
@@ -113,12 +112,14 @@ def main(args):
         print("Press Enter to exit")
 
     key = get_usable_keys(pattern=args[0])[0]
-
+    file_key_data = get_public_key_data(key.fingerprint)
+    hmac = mac_generate(key.fingerprint.encode('ascii'), file_key_data)
     offer = BluetoothOffer(key)
     code, _ = offer.allocate_code()
     offer.start().addCallback(_received)
     print("Offering key: {}".format(key))
     print("Discovery info: {}".format(code))
+    print("HMAC: {}".format(hmac))
     # Wait for the user without blocking everything
     reactor.callInThread(cancel)
     reactor.run()
diff --git a/keysign/bluetoothreceive.py b/keysign/bluetoothreceive.py
index c1f2072..73da028 100644
--- a/keysign/bluetoothreceive.py
+++ b/keysign/bluetoothreceive.py
@@ -104,8 +104,8 @@ class BluetoothReceive:
 
 def main(args):
     log.debug('Running main with args: %s', args)
-    if not args:
-        raise ValueError("You must provide an argument with the bluetooth code")
+    if not len(args) == 2:
+        raise ValueError("You must provide two arguments: bluetooth code and hmac")
 
     def _received(result):
         key_data, success, error_message = result
@@ -118,8 +118,9 @@ def main(args):
 
     print("Trying to download the key, please wait")
     bt_mac = args[0]
+    hmac = args[1]
     receive = BluetoothReceive()
-    d = receive.find_key(bt_mac)
+    d = receive.find_key(bt_mac, hmac)
     d.addCallback(_received)
     reactor.run()
 


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