diff --git a/dbus_service/dbus-service b/dbus_service/dbus-service index ff84755..dd8bc44 100755 --- a/dbus_service/dbus-service +++ b/dbus_service/dbus-service @@ -10,6 +10,7 @@ import dbus import dbus.mainloop.glib import dbus.service from binascii import hexlify, unhexlify +from threading import Thread dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) from gi.repository import GLib import logging @@ -92,19 +93,21 @@ class Device(dbus.service.Object): def VerifyStart(self, user, finger): logging.debug('In VerifyStart %s' % finger) - def complete_cb(rsp, e): - if e is not None: - self.VerifyStatus('verify-no-match', True) - else: - self.VerifyStatus('verify-match', True) - usrid, subtype, hsh = rsp - # TODO pass down the user DB id - # check that a correct finger was identified - def update_cb(e): self.VerifyStatus('verify-retry-scan', False) - sensor.identify(update_cb, complete_cb) + def run(): + try: + usrid, subtype, hsh = sensor.identify(update_cb) + self.VerifyStatus('verify-match', True) + except Exception as e: + logging.exception('Oops', e) + self.VerifyStatus('verify-no-match', True) + + thread = Thread(target=run) + thread.daemon = True + thread.start() + @dbus.service.method(dbus_interface=INTERFACE_NAME, in_signature='', @@ -112,18 +115,6 @@ class Device(dbus.service.Object): def Cancel(self): sensor.cancel() - def do_enroll(self, finger_name, uid): - # it is pointless to try and remember username passed in claim as Gnome does not seem to be passing anything useful anyway - try: - # TODO hardcode the username and finger for now - z=enroll(uid2identity(uid), 0xf5) - logging.debug('Enroll was successfull') - self.EnrollStatus('enroll-completed', True) - except Exception as e: - self.EnrollStatus('enroll-failed', True) - #loop.quit(); - raise e - @dbus.service.method(dbus_interface=INTERFACE_NAME, in_signature='ss', out_signature='') @@ -137,13 +128,18 @@ class Device(dbus.service.Object): else: self.EnrollStatus('enroll-stage-passed', False) - def complete_cb(rsp, e): - if e is not None: - self.EnrollStatus('enroll-failed', True) - else: + def run(): + try: + sensor.enroll(uid2identity(uid), 0xf5, update_cb) # TODO parse the finger name self.EnrollStatus('enroll-completed', True) + except Exception as e: + logging.exception('Oops', e) + self.EnrollStatus('enroll-failed', True) - sensor.enroll(uid2identity(uid), 0xf5, update_cb, complete_cb) # TODO parse the finger name + thread = Thread(target=run) + thread.daemon = True + thread.start() + @dbus.service.signal(dbus_interface=INTERFACE_NAME, signature='sb') def VerifyStatus(self, result, done): diff --git a/scripts/prototype.py b/scripts/prototype.py index 2d648f8..b015798 100644 --- a/scripts/prototype.py +++ b/scripts/prototype.py @@ -14,69 +14,21 @@ import code #tls.trace_enabled = True def identify(): - cv=Condition() - result=[] - def update_cb(e): print('Capture error: %s, try again' % repr(e)) - def complete_cb(rsp, e): - cv.acquire() - try: - result.append((rsp, e)) - cv.notify() - finally: - cv.release() - - sensor.identify(update_cb, complete_cb) - - cv.acquire() - try: - cv.wait() - rsp, e = result[0] - if e is not None: raise e - - except: - sensor.cancel() - raise - finally: - cv.release() - - usrid, subtype, hsh = rsp + usrid, subtype, hsh = sensor.identify(update_cb) print('Got finger %x for user recordid %d. Hash: %s' % (subtype, usrid, hexlify(hsh).decode())) def enroll(sid, finger): - cv=Condition() - result=[] - def update_cb(x, e): if e is not None: print('Enroll error: %s, try again' % repr(e)) else: print('Enroll progress: %s' % hexlify(x).decode()) - def complete_cb(rsp, e): - cv.acquire() - try: - result.append((rsp, e)) - cv.notify() - finally: - cv.release() - - sensor.enroll(sid, finger, update_cb, complete_cb) - - cv.acquire() - try: - cv.wait() - recid, e = result[0] - if e is not None: raise e - - except: - sensor.cancel() - raise - finally: - cv.release() + recid = sensor.enroll(sid, finger, update_cb) print('Created a finger record with dbid %d' % recid) diff --git a/validitysensor/db.py b/validitysensor/db.py index 486b6d7..b6da5f2 100644 --- a/validitysensor/db.py +++ b/validitysensor/db.py @@ -6,7 +6,7 @@ from .util import assert_status from struct import pack, unpack from binascii import hexlify, unhexlify from .blobs import db_write_enable -from .flash import flush_changes +from .flash import call_cleanups from .sid import * class UserStorage(): @@ -125,6 +125,18 @@ class DbRecord(): class Db(): + class Info(): + def __init__(self, total, used, free, records, roots): + self.total = total # partition size + self.used = used # used (not deleted) + self.free = free # unallocated space + self.records = records # total number, including deleted + self.roots = roots + + def __repr__(self): + return 'Db.Info(total=%d, used=%d, free=%d, records=%d, roots=%s)' % ( + self.total, self.used, self.free, self.records, repr(self.roots)) + def get_user_storage(self, dbid=0, name=''): name=name.encode() @@ -175,7 +187,7 @@ class Db(): rsp = rsp[14:] rec.children=[] for i in range(0, cnt): - dbid, typ = unpack(' 80: + val = val[:80] + '...' + print('%s%d (type %d) %s' % (' '*depth, rec.dbid, rec.type, val)) + + rec = self.get_record_children(root) + for c in rec.children: + self.dump_raw(c['dbid'], depth+1) + def dump_all(self): stg = self.get_user_storage(name='StgWindsor') usrs = [self.get_user(u['dbid']) for u in stg.users] diff --git a/validitysensor/flash.py b/validitysensor/flash.py index ce4dad8..6c00ea9 100644 --- a/validitysensor/flash.py +++ b/validitysensor/flash.py @@ -91,13 +91,19 @@ def get_fw_info(partition): def write_enable(): assert_status(tls.cmd(db_write_enable)) -def flush_changes(): - assert_status(tls.cmd(b'\x1a')) +def call_cleanups(): + rsp = tls.cmd(b'\x1a') + err = unpack(' 0: - tag, l = unpack(' 0: + tag, l = unpack('