Ejemplo n.º 1
0
async def respond_Features(ctx, msg):

    if msg.__qualname__ == 'Initialize':
        if msg.state is None or msg.state != cache.get_state(salt=msg.state[:32]):
            cache.clear()

    f = Features()
    f.vendor = 'trezor.io'
    f.major_version = symbol('VERSION_MAJOR')
    f.minor_version = symbol('VERSION_MINOR')
    f.patch_version = symbol('VERSION_PATCH')
    f.device_id = storage.get_device_id()
    f.pin_protection = config.has_pin()
    f.passphrase_protection = storage.has_passphrase()
    f.language = 'english'
    f.label = storage.get_label()
    f.coins = coins.COINS
    f.initialized = storage.is_initialized()
    f.revision = symbol('GITREV')
    f.pin_cached = config.has_pin()
    f.passphrase_cached = cache.has_passphrase()
    f.needs_backup = storage.needs_backup()
    f.flags = storage.get_flags()
    f.model = 'T'
    f.state = cache.get_state()

    return f
Ejemplo n.º 2
0
async def respond_Features(ctx, msg):
    from apps.common import storage, coins, cache
    from trezor.messages.Features import Features

    if msg.__qualname__ == 'Initialize':
        if msg.state is None or msg.state != cache.get_state():
            cache.clear()

    f = Features()
    f.vendor = 'trezor.io'
    f.revision = '0123456789'
    f.bootloader_hash = '0123456789'
    f.major_version = 2
    f.minor_version = 0
    f.patch_version = 0
    f.model = 'T'
    f.coins = coins.COINS

    f.device_id = storage.get_device_id()
    f.label = storage.get_label()
    f.initialized = storage.is_initialized()
    f.passphrase_protection = storage.has_passphrase()
    f.pin_protection = config.has_pin()
    f.language = 'english'

    f.state = cache.get_state()

    return f
Ejemplo n.º 3
0
async def respond_Features(ctx, msg):

    if msg.__qualname__ == 'Initialize':
        if msg.state is None or bytes(
                msg.state) != cache.get_state(state=bytes(msg.state)):
            cache.clear()

    f = Features()
    f.vendor = 'trezor.io'
    f.major_version = symbol('VERSION_MAJOR')
    f.minor_version = symbol('VERSION_MINOR')
    f.patch_version = symbol('VERSION_PATCH')
    f.device_id = storage.get_device_id()
    f.pin_protection = config.has_pin()
    f.passphrase_protection = storage.has_passphrase()
    f.language = 'english'
    f.label = storage.get_label()
    f.initialized = storage.is_initialized()
    f.revision = symbol('GITREV')
    f.pin_cached = config.has_pin()
    f.passphrase_cached = cache.has_passphrase()
    f.needs_backup = storage.needs_backup()
    f.flags = storage.get_flags()
    if model() in ['T', 'EMU']:  # emulator currently emulates model T
        f.model = 'T'
    f.unfinished_backup = storage.unfinished_backup()

    return f
Ejemplo n.º 4
0
def get_state(state: bytes = None, passphrase: str = None):

    if state is None:
        salt = random.bytes(32)  # generate a random salt if no state provided
    else:
        salt = state[:32]  # use salt from provided state

    if passphrase is None:
        global _passphrase
        if _passphrase is None:
            return None
        passphrase = _passphrase  # use cached passphrase

    # state = HMAC(passphrase, salt || device_id)
    msg = salt + storage.get_device_id().encode()
    state = hmac.new(passphrase.encode(), msg, hashlib.sha256).digest()

    return salt + state
Ejemplo n.º 5
0
def get_state(salt: bytes = None, passphrase: str = None):
    global _passphrase, _state_salt
    if salt is None:
        # generate a random salt if not provided and not already cached
        if _state_salt is None:
            _state_salt = random.bytes(32)
    else:
        # otherwise copy provided salt to cached salt
        _state_salt = salt

    # state = HMAC(passphrase, salt || device_id)
    if passphrase is None:
        key = _passphrase if _passphrase is not None else ''
    else:
        key = passphrase
    msg = _state_salt + storage.get_device_id().encode()
    state = hmac.new(key.encode(), msg, hashlib.sha256).digest()

    return _state_salt + state
Ejemplo n.º 6
0
def get_features():
    f = Features()
    f.vendor = "trezor.io"
    f.language = "english"
    f.major_version = utils.VERSION_MAJOR
    f.minor_version = utils.VERSION_MINOR
    f.patch_version = utils.VERSION_PATCH
    f.revision = utils.GITREV
    f.model = utils.MODEL
    f.device_id = storage.get_device_id()
    f.label = storage.get_label()
    f.initialized = storage.is_initialized()
    f.pin_protection = config.has_pin()
    f.pin_cached = config.has_pin()
    f.passphrase_protection = storage.has_passphrase()
    f.passphrase_cached = cache.has_passphrase()
    f.needs_backup = storage.needs_backup()
    f.unfinished_backup = storage.unfinished_backup()
    f.flags = storage.get_flags()
    return f
Ejemplo n.º 7
0
async def respond_Features(session_id, msg):
    from apps.common import storage, coins
    from trezor.messages.Features import Features

    f = Features()
    f.vendor = 'trezor.io'
    f.revision = '0123456789'
    f.bootloader_hash = '0123456789'
    f.major_version = 2
    f.minor_version = 0
    f.patch_version = 0
    f.coins = coins.COINS

    f.device_id = storage.get_device_id()
    f.label = storage.get_label()
    f.language = storage.get_language()
    f.initialized = storage.is_initialized()
    f.pin_protection = storage.is_protected_by_pin()
    f.passphrase_protection = storage.is_protected_by_passphrase()

    return f
Ejemplo n.º 8
0
def get_features():
    f = Features()
    f.vendor = 'trezor.io'
    f.language = 'english'
    f.major_version = utils.symbol('VERSION_MAJOR')
    f.minor_version = utils.symbol('VERSION_MINOR')
    f.patch_version = utils.symbol('VERSION_PATCH')
    f.revision = utils.symbol('GITREV')
    f.model = utils.model()
    if f.model == 'EMU':
        f.model = 'T'  # emulator currently emulates model T
    f.device_id = storage.get_device_id()
    f.label = storage.get_label()
    f.initialized = storage.is_initialized()
    f.pin_protection = config.has_pin()
    f.pin_cached = config.has_pin()
    f.passphrase_protection = storage.has_passphrase()
    f.passphrase_cached = cache.has_passphrase()
    f.needs_backup = storage.needs_backup()
    f.unfinished_backup = storage.unfinished_backup()
    f.flags = storage.get_flags()
    return f
Ejemplo n.º 9
0
            0x00,  # LOGICAL_MINIMUM (0)
            0x26,
            0xff,
            0x00,  # LOGICAL_MAXIMUM (255)
            0x75,
            0x08,  # REPORT_SIZE (8)
            0x95,
            0x40,  # REPORT_COUNT (64)
            0x91,
            0x02,  # OUTPUT (Data,Var,Abs)
            0xc0,  # END_COLLECTION
        ]),
    )

bus = io.USB(
    vendor_id=0x1209,
    product_id=0x53C1,
    release_num=0x0200,
    manufacturer="SatoshiLabs",
    product="TREZOR",
    interface="TREZOR Interface",
    serial_number=get_device_id(),
    usb21_landing=False,
)
bus.add(iface_wire)
if __debug__:
    bus.add(iface_debug)
    bus.add(iface_vcp)
else:
    bus.add(iface_u2f)
Ejemplo n.º 10
0
def _compute_state(salt: bytes, passphrase: str) -> bytes:
    # state = HMAC(passphrase, salt || device_id)
    message = salt + storage.get_device_id().encode()
    state = hmac.new(passphrase.encode(), message, hashlib.sha256).digest()
    return salt + state