From 885b6f72141b2f7b10a9216cc93d83fcc2238e78 Mon Sep 17 00:00:00 2001 From: Andrew Kozlik Date: Fri, 14 Aug 2020 10:06:53 +0200 Subject: [PATCH] feat(python): Support 50 digit PIN and wipe code in trezorctl. --- python/CHANGELOG.md | 2 ++ python/src/trezorlib/client.py | 5 ++++- python/src/trezorlib/ui.py | 10 +++++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/python/CHANGELOG.md b/python/CHANGELOG.md index 09507b3e0..486576a11 100644 --- a/python/CHANGELOG.md +++ b/python/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - protobuf is aware of `required` fields and default values - `btc.sign_tx()` accepts keyword arguments for transaction metadata [#1266] +- Support long PIN of up to 50 digits. [#1167] ### Deprecated @@ -509,6 +510,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#948]: https://github.com/trezor/trezor-firmware/issues/948 [#1052]: https://github.com/trezor/trezor-firmware/issues/1052 [#1126]: https://github.com/trezor/trezor-firmware/issues/1126 +[#1167]: https://github.com/trezor/trezor-firmware/issues/1167 [#1179]: https://github.com/trezor/trezor-firmware/issues/1179 [#1196]: https://github.com/trezor/trezor-firmware/issues/1196 [#1210]: https://github.com/trezor/trezor-firmware/issues/1210 diff --git a/python/src/trezorlib/client.py b/python/src/trezorlib/client.py index a75be139a..cd10380e0 100644 --- a/python/src/trezorlib/client.py +++ b/python/src/trezorlib/client.py @@ -29,6 +29,7 @@ LOG = logging.getLogger(__name__) VENDORS = ("bitcointrezor.com", "trezor.io") MAX_PASSPHRASE_LENGTH = 50 +MAX_PIN_LENGTH = 50 PASSPHRASE_ON_DEVICE = object() PASSPHRASE_TEST_PATH = tools.parse_path("44h/1h/0h/0/0") @@ -152,7 +153,9 @@ class TrezorClient: self.call_raw(messages.Cancel()) raise - if any(d not in "123456789" for d in pin) or not (1 <= len(pin) <= 9): + if any(d not in "123456789" for d in pin) or not ( + 1 <= len(pin) <= MAX_PIN_LENGTH + ): self.call_raw(messages.Cancel()) raise ValueError("Invalid PIN provided") diff --git a/python/src/trezorlib/ui.py b/python/src/trezorlib/ui.py index 479d76f91..bbdf09fa5 100644 --- a/python/src/trezorlib/ui.py +++ b/python/src/trezorlib/ui.py @@ -20,7 +20,7 @@ import click from mnemonic import Mnemonic from . import device -from .client import PASSPHRASE_ON_DEVICE +from .client import MAX_PIN_LENGTH, PASSPHRASE_ON_DEVICE from .exceptions import Cancelled from .messages import PinMatrixRequestType, WordRequestType @@ -107,8 +107,12 @@ class ClickUI: echo( "The value may only consist of digits 1 to 9 or letters cvbdfgert." ) - elif len(pin) > 9: - echo("The value must be at most 9 digits in length.") + elif len(pin) > MAX_PIN_LENGTH: + echo( + "The value must be at most {} digits in length.".format( + MAX_PIN_LENGTH + ) + ) else: return pin