New reformatting of code after rebase and changes.

This commit is contained in:
Arvid Norlander 2020-08-06 11:53:03 +02:00
parent 9f116547d0
commit 4417e49612
No known key found for this signature in database
GPG key ID: E824A8E5D8D29AA0
13 changed files with 51 additions and 52 deletions

View file

@ -158,11 +158,9 @@ class Device(dbus.service.Object):
logging.exception(e)
self.EnrollStatus('enroll-failed', True)
if index == None:
logging.exception(
'Unknown finger name passed to enroll? ' +
finger_name + ' (' + winbio_name + ')'
)
if index is None:
logging.exception('Unknown finger name passed to enroll? ' + finger_name + ' (' +
winbio_name + ')')
self.EnrollStatus('enroll-failed', True)
else:
thread = Thread(target=run)

View file

@ -1,5 +1,5 @@
from validitysensor.usb import usb
from validitysensor.sensor import factory_reset, RebootException
from validitysensor.usb import usb
try:
usb.open()

View file

@ -1,6 +1,7 @@
#!/usr/bin/env python3
import dbus.mainloop.glib
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()

View file

@ -2,7 +2,6 @@ from binascii import hexlify
from validitysensor.sensor import sensor
# usb.trace_enabled = True
# tls.trace_enabled = True

View file

@ -1,6 +1,6 @@
import typing
from binascii import hexlify
from struct import pack, unpack
import typing
from .blobs import db_write_enable
from .flash import call_cleanups

View file

@ -80,7 +80,8 @@ class ModuleInfo:
class FirmwareInfo:
def __init__(self, major: int, minor: int, buildtime: int, modules: typing.Sequence[ModuleInfo]):
def __init__(self, major: int, minor: int, buildtime: int,
modules: typing.Sequence[ModuleInfo]):
self.major, self.minor, self.buildtime, self.modules = major, minor, buildtime, modules
def __repr__(self):

View file

@ -408,7 +408,8 @@ class Sensor:
return key_line
def line_update_type_1(self, mode: CaptureMode, chunks: typing.List[typing.List[typing.Union[int, bytes]]]):
def line_update_type_1(self, mode: CaptureMode,
chunks: typing.List[typing.List[typing.Union[int, bytes]]]):
for c in chunks:
# Timeslot Table 2D
if c[0] == 0x34:
@ -511,11 +512,12 @@ class Sensor:
return chunks
def line_update_type_2(self, mode: CaptureMode, chunks: typing.List[typing.List[typing.Union[int, bytes]]]):
def line_update_type_2(self, mode: CaptureMode,
chunks: typing.List[typing.List[typing.Union[int, bytes]]]):
for c in chunks:
# patch the 2D params.
# The following is only needed on some rom versions below 6.5 as reported by cmd_01
#if c[0] == 0x2f:
# if c[0] == 0x2f:
# c[1] = pack('<L', unpack('<L', c[1])[0]*mult)
# Timeslot Table 2D
@ -589,7 +591,7 @@ class Sensor:
if pad > 0:
l.data += b'\0' * (4 - pad)
#---------------- Line Update ---------------
# ---------------- Line Update ---------------
line_update = pack('<L', len(lines))
line_update += b''.join([pack('<LL', l.mask, l.flags) for l in lines])

View file

@ -13,8 +13,8 @@ class SensorTypeInfo:
if i.sensor_type == sensor_type:
return i
def __init__(self, sensor_type: int, bytes_per_line: int, repeat_multiplier: int, lines_per_calibration_data: int,
line_width: int, calibration_blob: str):
def __init__(self, sensor_type: int, bytes_per_line: int, repeat_multiplier: int,
lines_per_calibration_data: int, line_width: int, calibration_blob: str):
self.sensor_type = sensor_type
self.repeat_multiplier = repeat_multiplier
self.lines_per_calibration_data = lines_per_calibration_data

View file

@ -1,6 +1,6 @@
import typing
from binascii import hexlify
from struct import unpack, pack
import typing
codes = {}
codes[0x0] = "No Operation"

View file

@ -197,7 +197,7 @@ class Tls:
return m
def encrypt(self, b: bytes):
#iv = unhexlify('454849acdd075174d6b9e713a957c2e7')
# iv = unhexlify('454849acdd075174d6b9e713a957c2e7')
iv = os.urandom(0x10)
cipher = Cipher(algorithms.AES(self.encryption_key), modes.CBC(iv), backend=crypto_backend)
encryptor = cipher.encryptor()
@ -383,7 +383,7 @@ class Tls:
def make_client_hello(self):
h = unhexlify('0303') # TLS 1.2
#self.client_random = unhexlify('bc349559ac16c8f8362191395b4d04a435d870315f519eed8777488bc2b9600c')
# self.client_random = unhexlify('bc349559ac16c8f8362191395b4d04a435d870315f519eed8777488bc2b9600c')
self.client_random = os.urandom(0x20)
h += self.client_random # client's random
h += with_1byte_size(unhexlify('00000000000000')) # session ID
@ -533,8 +533,8 @@ class Tls:
self.trace('d=0x%x' % d)
# Someone has reported that x and y are 0 after pairing with the latest windows driver.
#pub_key = ec.EllipticCurvePublicNumbers(x, y, ec.SECP256R1())
#self.priv_key = ec.EllipticCurvePrivateNumbers(d, pub_key).private_key(crypto_backend)
# pub_key = ec.EllipticCurvePublicNumbers(x, y, ec.SECP256R1())
# self.priv_key = ec.EllipticCurvePrivateNumbers(d, pub_key).private_key(crypto_backend)
self.priv_key = ec.derive_private_key(d, ec.SECP256R1(), backend=crypto_backend)

View file

@ -1,7 +1,7 @@
import logging
import typing
from os.path import basename
from time import ctime
import typing
from .flash import write_flash_all, write_fw_signature, get_fw_info
from .sensor import reboot, write_hw_reg32, read_hw_reg32, identify_sensor
@ -22,7 +22,7 @@ def default_fwext_name():
return '6_07f_lenovo_mis_qm.xpfwext'
def upload_fwext(fw_path: typing.Optional[str]=None):
def upload_fwext(fw_path: typing.Optional[str] = None):
fwi = get_fw_info(2)
if fwi is not None:
logging.info('Detected firmware version %d.%d (%s))' %

View file

@ -1,8 +1,8 @@
import errno
import logging
import typing
from binascii import hexlify, unhexlify
from struct import unpack
import typing
import usb.core as ucore
from usb.core import USBError

View file

@ -1,36 +1,34 @@
finger_ids = {
# https://github.com/tpn/winsdk-10/blob/9b69fd26ac0c7d0b83d378dba01080e93349c2ed/Include/10.0.16299.0/shared/winbio_types.h#L864-L878
"WINBIO_ANSI_381_POS_UNKNOWN": 0,
"WINBIO_ANSI_381_POS_RH_THUMB": 1,
"WINBIO_ANSI_381_POS_RH_INDEX_FINGER": 2,
"WINBIO_ANSI_381_POS_RH_MIDDLE_FINGER": 3,
"WINBIO_ANSI_381_POS_RH_RING_FINGER": 4,
"WINBIO_ANSI_381_POS_RH_LITTLE_FINGER": 5,
"WINBIO_ANSI_381_POS_LH_THUMB": 6,
"WINBIO_ANSI_381_POS_LH_INDEX_FINGER": 7,
"WINBIO_ANSI_381_POS_LH_MIDDLE_FINGER": 8,
"WINBIO_ANSI_381_POS_LH_RING_FINGER": 9,
"WINBIO_ANSI_381_POS_LH_LITTLE_FINGER": 10,
# https://github.com/tpn/winsdk-10/blob/9b69fd26ac0c7d0b83d378dba01080e93349c2ed/Include/10.0.16299.0/shared/winbio_types.h#L864-L878
"WINBIO_ANSI_381_POS_UNKNOWN": 0,
"WINBIO_ANSI_381_POS_RH_THUMB": 1,
"WINBIO_ANSI_381_POS_RH_INDEX_FINGER": 2,
"WINBIO_ANSI_381_POS_RH_MIDDLE_FINGER": 3,
"WINBIO_ANSI_381_POS_RH_RING_FINGER": 4,
"WINBIO_ANSI_381_POS_RH_LITTLE_FINGER": 5,
"WINBIO_ANSI_381_POS_LH_THUMB": 6,
"WINBIO_ANSI_381_POS_LH_INDEX_FINGER": 7,
"WINBIO_ANSI_381_POS_LH_MIDDLE_FINGER": 8,
"WINBIO_ANSI_381_POS_LH_RING_FINGER": 9,
"WINBIO_ANSI_381_POS_LH_LITTLE_FINGER": 10,
"WINBIO_ANSI_381_POS_RH_FOUR_FINGERS": 13,
"WINBIO_ANSI_381_POS_LH_FOUR_FINGERS": 14,
"WINBIO_ANSI_381_POS_TWO_THUMBS": 15,
"WINBIO_ANSI_381_POS_RH_FOUR_FINGERS": 13,
"WINBIO_ANSI_381_POS_LH_FOUR_FINGERS": 14,
"WINBIO_ANSI_381_POS_TWO_THUMBS": 15,
# https://github.com/tpn/winsdk-10/blob/9b69fd26ac0c7d0b83d378dba01080e93349c2ed/Include/10.0.16299.0/shared/winbio_types.h#L920-L929
"WINBIO_FINGER_UNSPECIFIED_POS_01": 0xf5,
"WINBIO_FINGER_UNSPECIFIED_POS_02": 0xf6,
"WINBIO_FINGER_UNSPECIFIED_POS_03": 0xf7,
"WINBIO_FINGER_UNSPECIFIED_POS_04": 0xf8,
"WINBIO_FINGER_UNSPECIFIED_POS_05": 0xf9,
"WINBIO_FINGER_UNSPECIFIED_POS_06": 0xfa,
"WINBIO_FINGER_UNSPECIFIED_POS_07": 0xfb,
"WINBIO_FINGER_UNSPECIFIED_POS_08": 0xfc,
"WINBIO_FINGER_UNSPECIFIED_POS_09": 0xfd,
"WINBIO_FINGER_UNSPECIFIED_POS_10": 0xfe
# https://github.com/tpn/winsdk-10/blob/9b69fd26ac0c7d0b83d378dba01080e93349c2ed/Include/10.0.16299.0/shared/winbio_types.h#L920-L929
"WINBIO_FINGER_UNSPECIFIED_POS_01": 0xf5,
"WINBIO_FINGER_UNSPECIFIED_POS_02": 0xf6,
"WINBIO_FINGER_UNSPECIFIED_POS_03": 0xf7,
"WINBIO_FINGER_UNSPECIFIED_POS_04": 0xf8,
"WINBIO_FINGER_UNSPECIFIED_POS_05": 0xf9,
"WINBIO_FINGER_UNSPECIFIED_POS_06": 0xfa,
"WINBIO_FINGER_UNSPECIFIED_POS_07": 0xfb,
"WINBIO_FINGER_UNSPECIFIED_POS_08": 0xfc,
"WINBIO_FINGER_UNSPECIFIED_POS_09": 0xfd,
"WINBIO_FINGER_UNSPECIFIED_POS_10": 0xfe
}
# Store the keys in the reverse order for faster lookups
finger_names = {}
for name, index in finger_ids.items():
finger_names[index] = name
finger_names[index] = name