コード例 #1
0
ファイル: device.py プロジェクト: umbru/trezor-firmware
def load_settings(
    label: str = None,
    use_passphrase: bool = None,
    homescreen: bytes = None,
    passphrase_source: int = None,
    display_rotation: int = None,
) -> None:
    if label is not None:
        common._set(_NAMESPACE, _LABEL, label.encode(), True)  # public
    if use_passphrase is not None:
        common._set_bool(_NAMESPACE, _USE_PASSPHRASE, use_passphrase)
    if homescreen is not None:
        if homescreen[:8] == b"TOIf\x90\x00\x90\x00":
            if len(homescreen) <= HOMESCREEN_MAXSIZE:
                common._set(_NAMESPACE, _HOMESCREEN, homescreen,
                            True)  # public
        else:
            common._set(_NAMESPACE, _HOMESCREEN, b"", True)  # public
    if passphrase_source is not None:
        if passphrase_source in (0, 1, 2):
            common._set(_NAMESPACE, _PASSPHRASE_SOURCE,
                        bytes([passphrase_source]))
    if display_rotation is not None:
        if display_rotation not in (0, 90, 180, 270):
            raise ValueError("Unsupported display rotation degrees: %d" %
                             display_rotation)
        else:
            common._set(_NAMESPACE, _ROTATION,
                        display_rotation.to_bytes(2, "big"), True)  # public
コード例 #2
0
def store_resident_credential(cred: Fido2Credential) -> bool:
    slot = None
    for i in range(
            _RESIDENT_CREDENTIAL_START_KEY,
            _RESIDENT_CREDENTIAL_START_KEY + _MAX_RESIDENT_CREDENTIALS,
    ):
        stored_cred_data = common._get(common._APP_FIDO2, i)
        if stored_cred_data is None:
            if slot is None:
                slot = i
            continue

        stored_rp_id_hash = stored_cred_data[:32]
        stored_cred_id = stored_cred_data[32:]

        if cred.rp_id_hash != stored_rp_id_hash:
            # Stored credential is not for this RP ID.
            continue

        stored_cred = Fido2Credential.from_cred_id(stored_cred_id,
                                                   stored_rp_id_hash)
        if stored_cred is None:
            # Stored credential is not for this RP ID.
            continue

        # If a credential for the same RP ID and user ID already exists, then overwrite it.
        if stored_cred.user_id == cred.user_id:
            slot = i
            break

    if slot is None:
        return False

    common._set(common._APP_FIDO2, slot, cred.rp_id_hash + cred.id)
    return True
コード例 #3
0
ファイル: device.py プロジェクト: umbru/trezor-firmware
def set_flags(flags: int) -> None:
    b = common._get(_NAMESPACE, _FLAGS)
    if b is None:
        i = 0
    else:
        i = int.from_bytes(b, "big")
    flags = (flags | i) & 0xFFFFFFFF
    if flags != i:
        common._set(_NAMESPACE, _FLAGS, flags.to_bytes(4, "big"))
コード例 #4
0
ファイル: device.py プロジェクト: umbru/trezor-firmware
def store_mnemonic_secret(
    secret: bytes,
    mnemonic_type: int,
    needs_backup: bool = False,
    no_backup: bool = False,
) -> None:
    set_version(common._STORAGE_VERSION_CURRENT)
    common._set(_NAMESPACE, _MNEMONIC_SECRET, secret)
    common._set_uint8(_NAMESPACE, _MNEMONIC_TYPE, mnemonic_type)
    common._set_true_or_delete(_NAMESPACE, _NO_BACKUP, no_backup)
    if not no_backup:
        common._set_true_or_delete(_NAMESPACE, _NEEDS_BACKUP, needs_backup)
コード例 #5
0
ファイル: device.py プロジェクト: umbru/trezor-firmware
def get_device_id() -> str:
    dev_id = common._get(_NAMESPACE, _DEVICE_ID, True)  # public
    if not dev_id:
        dev_id = _new_device_id().encode()
        common._set(_NAMESPACE, _DEVICE_ID, dev_id, True)  # public
    return dev_id.decode()
コード例 #6
0
ファイル: device.py プロジェクト: umbru/trezor-firmware
def set_version(version: bytes) -> None:
    common._set(_NAMESPACE, _VERSION, version)
コード例 #7
0
ファイル: device.py プロジェクト: umbru/trezor-firmware
def set_autolock_delay_ms(delay_ms: int) -> None:
    if delay_ms < 60 * 1000:
        delay_ms = 60 * 1000
    common._set(_NAMESPACE, _AUTOLOCK_DELAY_MS, delay_ms.to_bytes(4, "big"))
コード例 #8
0
def set(index: int, mnemonic: str) -> None:
    common._set(common._APP_RECOVERY_SHARES, index, mnemonic.encode())
コード例 #9
0
def set(index: int, mnemonic: str) -> None:
    common._set(common._APP_SLIP39_MNEMONICS, index, mnemonic.encode())