Basic status icon working
This commit is contained in:
parent
9249e792a1
commit
b84de745fa
2 changed files with 50 additions and 35 deletions
|
|
@ -208,8 +208,6 @@ class NoiseEngine:
|
||||||
self.proto.start_handshake()
|
self.proto.start_handshake()
|
||||||
self.paired = False
|
self.paired = False
|
||||||
self.connected = False
|
self.connected = False
|
||||||
self.packetizer.send_packet(PacketType.INITIATE_HANDSHAKE, b'')
|
|
||||||
self.debug_print('Handshake started')
|
|
||||||
|
|
||||||
@wraps(print)
|
@wraps(print)
|
||||||
def debug_print(self, *args, **kwargs):
|
def debug_print(self, *args, **kwargs):
|
||||||
|
|
@ -217,6 +215,9 @@ class NoiseEngine:
|
||||||
print(*args, **kwargs)
|
print(*args, **kwargs)
|
||||||
|
|
||||||
def perform_handshake(self):
|
def perform_handshake(self):
|
||||||
|
self.packetizer.send_packet(PacketType.INITIATE_HANDSHAKE, b'')
|
||||||
|
self.debug_print('Handshake started')
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if self.proto.handshake_finished:
|
if self.proto.handshake_finished:
|
||||||
break
|
break
|
||||||
|
|
|
||||||
80
pairing.py
80
pairing.py
|
|
@ -10,9 +10,9 @@ from gi.repository import Gtk, Gdk, Pango, GLib
|
||||||
import hexnoise
|
import hexnoise
|
||||||
|
|
||||||
class PairingWindow(Gtk.Window):
|
class PairingWindow(Gtk.Window):
|
||||||
def __init__(self, serial, debug=False):
|
def __init__(self, noise, debug=False):
|
||||||
Gtk.Window.__init__(self, title='SecureHID pairing')
|
Gtk.Window.__init__(self, title='SecureHID pairing')
|
||||||
self.serial = serial
|
self.noise = noise
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
|
|
||||||
self.set_border_width(10)
|
self.set_border_width(10)
|
||||||
|
|
@ -36,9 +36,6 @@ class PairingWindow(Gtk.Window):
|
||||||
self.handshaker.start()
|
self.handshaker.start()
|
||||||
|
|
||||||
def pair(self):
|
def pair(self):
|
||||||
self.packetizer = hexnoise.Packetizer(self.serial, debug=self.debug)
|
|
||||||
self.noise = hexnoise.NoiseEngine(self.packetizer, debug=self.debug)
|
|
||||||
|
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
try:
|
try:
|
||||||
self.run_handshake()
|
self.run_handshake()
|
||||||
|
|
@ -47,34 +44,56 @@ class PairingWindow(Gtk.Window):
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
def run_handshake(self):
|
def run_handshake(self):
|
||||||
self.noise.perform_handshake()
|
binding_incantation = self.noise.channel_binding_incantation()
|
||||||
|
GLib.idle_add(self.label.set_markup,
|
||||||
|
f'<b>Step 2</b>\n\nPerform channel binding ritual.\n'
|
||||||
|
f'Enter the following incantation, then press enter.\n'
|
||||||
|
f'<b>{binding_incantation}</b>')
|
||||||
|
|
||||||
|
def update_text(text):
|
||||||
|
self.entry.set_text(text)
|
||||||
|
self.entry.set_position(len(text))
|
||||||
|
|
||||||
if not self.noise.paired:
|
clean = lambda s: re.sub('[^a-z0-9-]', '', s.lower())
|
||||||
binding_incantation = self.noise.channel_binding_incantation()
|
if clean(binding_incantation).startswith(clean(text)):
|
||||||
GLib.idle_add(self.label.set_markup,
|
color = 0.9, 1.0, 0.9 # light red
|
||||||
f'<b>Step 2</b>\n\nPerform channel binding ritual.\n'
|
else:
|
||||||
f'Enter the following incantation, then press enter.\n'
|
color = 1.0, 0.9, 0.9 # light green
|
||||||
f'<b>{binding_incantation}</b>')
|
self.entry.override_background_color(Gtk.StateType.NORMAL, Gdk.RGBA(*color, 1.0))
|
||||||
|
|
||||||
def update_text(text):
|
|
||||||
self.entry.set_text(text)
|
|
||||||
self.entry.set_position(len(text))
|
|
||||||
|
|
||||||
clean = lambda s: re.sub('[^a-z0-9-]', '', s.lower())
|
|
||||||
if clean(binding_incantation).startswith(clean(text)):
|
|
||||||
color = 0.9, 1.0, 0.9 # light red
|
|
||||||
else:
|
|
||||||
color = 1.0, 0.9, 0.9 # light green
|
|
||||||
self.entry.override_background_color(Gtk.StateType.NORMAL, Gdk.RGBA(*color, 1.0))
|
|
||||||
|
|
||||||
|
try:
|
||||||
for user_input in self.noise.pairing_messages():
|
for user_input in self.noise.pairing_messages():
|
||||||
print(f'User input: "{user_input}"')
|
|
||||||
GLib.idle_add(update_text, user_input)
|
GLib.idle_add(update_text, user_input)
|
||||||
|
self.destroy()
|
||||||
|
except noise.ProtocolError as e:
|
||||||
|
GLib.idle_add(self.label.set_markup, f'<b>Error: {e}!</b>')
|
||||||
|
|
||||||
GLib.idle_add(self.label.set_markup, f'<b>Done!</b>')
|
|
||||||
|
|
||||||
# FIXME demo
|
class StatusIcon(Gtk.StatusIcon):
|
||||||
self.noise.uinput_passthrough()
|
def __init__(self):
|
||||||
|
Gtk.StatusIcon.__init__(self)
|
||||||
|
self.set_tooltip_text('SecureHID connected')
|
||||||
|
self.set_from_file('secureusb_icon.png')
|
||||||
|
|
||||||
|
|
||||||
|
def run_pairing_gui(serial, baudrate, debug=False):
|
||||||
|
ser = serial.Serial(serial, baudrate)
|
||||||
|
packetizer = hexnoise.Packetizer(serial, debug=debug)
|
||||||
|
noise = hexnoise.NoiseEngine(packetizer, debug=debug)
|
||||||
|
noise.perform_handshake()
|
||||||
|
|
||||||
|
if not noise.paired:
|
||||||
|
window = PairingWindow(noise, debug=debug)
|
||||||
|
window.connect('destroy', Gtk.main_quit)
|
||||||
|
window.show_all()
|
||||||
|
Gtk.main()
|
||||||
|
|
||||||
|
if self.noise.paired:
|
||||||
|
input_runner = threading.Thread(target=noise.uinput_passthrough, daemon=True)
|
||||||
|
input_runner.start()
|
||||||
|
|
||||||
|
status_icon = StatusIcon()
|
||||||
|
Gtk.main()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import argparse
|
import argparse
|
||||||
|
|
@ -84,10 +103,5 @@ if __name__ == '__main__':
|
||||||
parser.add_argument('-d', '--debug', action='store_true')
|
parser.add_argument('-d', '--debug', action='store_true')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
ser = serial.Serial(args.serial, args.baudrate)
|
run_pairing_gui(args.serial, args.baudrate, args.debug)
|
||||||
|
|
||||||
window = PairingWindow(ser, debug=args.debug)
|
|
||||||
window.connect('destroy', Gtk.main_quit)
|
|
||||||
window.show_all()
|
|
||||||
Gtk.main()
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue