diff --git a/common/protob/messages-management.proto b/common/protob/messages-management.proto index 24dd382759..129493828d 100644 --- a/common/protob/messages-management.proto +++ b/common/protob/messages-management.proto @@ -5,8 +5,6 @@ package hw.trezor.messages.management; option java_package = "com.satoshilabs.trezor.lib.protobuf"; option java_outer_classname = "TrezorMessageManagement"; -import "messages-common.proto"; - /** * Type of the mnemonic backup given/received by the device during reset/recovery. */ @@ -216,7 +214,6 @@ message WipeDevice { */ message LoadDevice { repeated string mnemonics = 1; // seed encoded as mnemonic (12, 18 or 24 words for BIP39, 20 or 33 for SLIP39) - optional hw.trezor.messages.common.HDNodeType node = 2; // BIP-32 node optional string pin = 3; // set PIN protection optional bool passphrase_protection = 4; // enable master node encryption using passphrase optional string language = 5 [default='english']; // device language diff --git a/core/src/apps/management/load_device.py b/core/src/apps/management/load_device.py index c9b9fc27a9..7227bc6683 100644 --- a/core/src/apps/management/load_device.py +++ b/core/src/apps/management/load_device.py @@ -55,9 +55,6 @@ def _validate(msg) -> int: if storage.is_initialized(): raise wire.UnexpectedMessage("Already initialized") - if msg.node is not None: - raise wire.ProcessError("LoadDevice.node is not supported") - if not msg.mnemonics: raise wire.ProcessError("No mnemonic provided") diff --git a/core/src/trezor/messages/LoadDevice.py b/core/src/trezor/messages/LoadDevice.py index db9a43200d..a9d19c2ffc 100644 --- a/core/src/trezor/messages/LoadDevice.py +++ b/core/src/trezor/messages/LoadDevice.py @@ -2,8 +2,6 @@ # fmt: off import protobuf as p -from .HDNodeType import HDNodeType - if __debug__: try: from typing import Dict, List # noqa: F401 @@ -18,7 +16,6 @@ class LoadDevice(p.MessageType): def __init__( self, mnemonics: List[str] = None, - node: HDNodeType = None, pin: str = None, passphrase_protection: bool = None, language: str = None, @@ -29,7 +26,6 @@ class LoadDevice(p.MessageType): no_backup: bool = None, ) -> None: self.mnemonics = mnemonics if mnemonics is not None else [] - self.node = node self.pin = pin self.passphrase_protection = passphrase_protection self.language = language @@ -43,7 +39,6 @@ class LoadDevice(p.MessageType): def get_fields(cls) -> Dict: return { 1: ('mnemonics', p.UnicodeType, p.FLAG_REPEATED), - 2: ('node', HDNodeType, 0), 3: ('pin', p.UnicodeType, 0), 4: ('passphrase_protection', p.BoolType, 0), 5: ('language', p.UnicodeType, 0), # default=english diff --git a/legacy/firmware/config.c b/legacy/firmware/config.c index 3db52ea3ed..918571c1e6 100644 --- a/legacy/firmware/config.c +++ b/legacy/firmware/config.c @@ -21,6 +21,7 @@ #include #include +#include "messages-common.pb.h" #include "messages.pb.h" #include "aes/aes.h" @@ -438,27 +439,6 @@ static void config_compute_u2froot(const char *mnemonic, session_clear(false); // invalidate seed cache } -static void config_setNode(const HDNodeType *node) { - StorageHDNode storageHDNode = {0}; - memzero(&storageHDNode, sizeof(storageHDNode)); - - storageHDNode.depth = node->depth; - storageHDNode.fingerprint = node->fingerprint; - storageHDNode.child_num = node->child_num; - storageHDNode.chain_code.size = 32; - memcpy(storageHDNode.chain_code.bytes, node->chain_code.bytes, 32); - - if (node->has_private_key) { - storageHDNode.has_private_key = true; - storageHDNode.private_key.size = 32; - memcpy(storageHDNode.private_key.bytes, node->private_key.bytes, 32); - } - if (sectrue == storage_set(KEY_NODE, &storageHDNode, sizeof(storageHDNode))) { - config_set_bool(KEY_INITIALIZED, true); - } - memzero(&storageHDNode, sizeof(storageHDNode)); -} - #if DEBUG_LINK bool config_dumpNode(HDNodeType *node) { @@ -500,10 +480,7 @@ void config_loadDevice(const LoadDevice *msg) { config_changePin("", msg->pin); } - if (msg->has_node) { - storage_delete(KEY_MNEMONIC); - config_setNode(&(msg->node)); - } else if (msg->mnemonics_count) { + if (msg->mnemonics_count) { storage_delete(KEY_NODE); config_setMnemonic(msg->mnemonics[0]); } diff --git a/legacy/firmware/config.h b/legacy/firmware/config.h index 8deb69ff4a..31c7f3c8b0 100644 --- a/legacy/firmware/config.h +++ b/legacy/firmware/config.h @@ -21,6 +21,7 @@ #define __CONFIG_H__ #include "bip32.h" +#include "messages-common.pb.h" #include "messages-management.pb.h" #define STORAGE_FIELD(TYPE, NAME) \ diff --git a/python/src/trezorlib/cli/trezorctl.py b/python/src/trezorlib/cli/trezorctl.py index 551db21b53..2925976d6e 100755 --- a/python/src/trezorlib/cli/trezorctl.py +++ b/python/src/trezorlib/cli/trezorctl.py @@ -456,8 +456,6 @@ def wipe_device(connect, bootloader): @cli.command(help="Load custom configuration to the device.") @click.option("-m", "--mnemonic", multiple=True) -@click.option("-e", "--expand", is_flag=True) -@click.option("-x", "--xprv") @click.option("-p", "--pin", default="") @click.option("-r", "--passphrase-protection", is_flag=True) @click.option("-l", "--label", default="") @@ -475,25 +473,17 @@ def load_device( ignore_checksum, slip0014, ): - n_args = sum(bool(a) for a in (mnemonic, xprv, slip0014)) - if n_args == 0: - raise click.ClickException("Please provide a mnemonic or xprv") - if n_args > 1: - raise click.ClickException("Cannot use mnemonic and xprv together") + if slip0014 and mnemonic: + raise click.ClickException("Cannot use -s and -m together.") client = connect() - if xprv: - return debuglink.load_device_by_xprv( - client, xprv, pin, passphrase_protection, label, "english" - ) - if slip0014: mnemonic = [" ".join(["all"] * 12)] if not label: label = "SLIP-0014" - return debuglink.load_device_by_mnemonic( + return debuglink.load_device( client, list(mnemonic), pin, diff --git a/python/src/trezorlib/debuglink.py b/python/src/trezorlib/debuglink.py index 43df7f2a5a..a8ee033ed9 100644 --- a/python/src/trezorlib/debuglink.py +++ b/python/src/trezorlib/debuglink.py @@ -19,7 +19,7 @@ from copy import deepcopy from mnemonic import Mnemonic -from . import messages as proto, protobuf, tools +from . import messages as proto, protobuf from .client import TrezorClient from .tools import expect @@ -483,56 +483,6 @@ def load_device_by_mnemonic( return resp -@expect(proto.Success, field="message") -def load_device_by_xprv(client, xprv, pin, passphrase_protection, label, language): - if client.features.initialized: - raise RuntimeError( - "Device is initialized already. Call wipe_device() and try again." - ) - - if xprv[0:4] not in ("xprv", "tprv"): - raise ValueError("Unknown type of xprv") - - if not 100 < len(xprv) < 112: # yes this is correct in Python - raise ValueError("Invalid length of xprv") - - node = proto.HDNodeType() - data = tools.b58decode(xprv, None).hex() - - if data[90:92] != "00": - raise ValueError("Contain invalid private key") - - checksum = (tools.btc_hash(bytes.fromhex(data[:156]))[:4]).hex() - if checksum != data[156:]: - raise ValueError("Checksum doesn't match") - - # version 0488ade4 - # depth 00 - # fingerprint 00000000 - # child_num 00000000 - # chaincode 873dff81c02f525623fd1fe5167eac3a55a049de3d314bb42ee227ffed37d508 - # privkey 00e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35 - # checksum e77e9d71 - - node.depth = int(data[8:10], 16) - node.fingerprint = int(data[10:18], 16) - node.child_num = int(data[18:26], 16) - node.chain_code = bytes.fromhex(data[26:90]) - node.private_key = bytes.fromhex(data[92:156]) # skip 0x00 indicating privkey - - resp = client.call( - proto.LoadDevice( - node=node, - pin=pin, - passphrase_protection=passphrase_protection, - language=language, - label=label, - ) - ) - client.init_device() - return resp - - @expect(proto.Success, field="message") def self_test(client): if client.features.bootloader_mode is not True: diff --git a/python/src/trezorlib/messages/LoadDevice.py b/python/src/trezorlib/messages/LoadDevice.py index 680f2be724..d9eef5e7fa 100644 --- a/python/src/trezorlib/messages/LoadDevice.py +++ b/python/src/trezorlib/messages/LoadDevice.py @@ -2,8 +2,6 @@ # fmt: off from .. import protobuf as p -from .HDNodeType import HDNodeType - if __debug__: try: from typing import Dict, List # noqa: F401 @@ -18,7 +16,6 @@ class LoadDevice(p.MessageType): def __init__( self, mnemonics: List[str] = None, - node: HDNodeType = None, pin: str = None, passphrase_protection: bool = None, language: str = None, @@ -29,7 +26,6 @@ class LoadDevice(p.MessageType): no_backup: bool = None, ) -> None: self.mnemonics = mnemonics if mnemonics is not None else [] - self.node = node self.pin = pin self.passphrase_protection = passphrase_protection self.language = language @@ -43,7 +39,6 @@ class LoadDevice(p.MessageType): def get_fields(cls) -> Dict: return { 1: ('mnemonics', p.UnicodeType, p.FLAG_REPEATED), - 2: ('node', HDNodeType, 0), 3: ('pin', p.UnicodeType, 0), 4: ('passphrase_protection', p.BoolType, 0), 5: ('language', p.UnicodeType, 0), # default=english diff --git a/tests/device_tests/test_msg_loaddevice_xprv.py b/tests/device_tests/test_msg_loaddevice_xprv.py deleted file mode 100644 index 17473b0e70..0000000000 --- a/tests/device_tests/test_msg_loaddevice_xprv.py +++ /dev/null @@ -1,58 +0,0 @@ -# This file is part of the Trezor project. -# -# Copyright (C) 2012-2019 SatoshiLabs and contributors -# -# This library is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License version 3 -# as published by the Free Software Foundation. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the License along with this library. -# If not, see . - -import pytest - -from trezorlib import btc, debuglink - - -@pytest.mark.skip_t2 -class TestDeviceLoadXprv: - @pytest.mark.setup_client(uninitialized=True) - def test_load_device_xprv_1(self, client): - debuglink.load_device_by_xprv( - client, - xprv="xprv9s21ZrQH143K2JF8RafpqtKiTbsbaxEeUaMnNHsm5o6wCW3z8ySyH4UxFVSfZ8n7ESu7fgir8imbZKLYVBxFPND1pniTZ81vKfd45EHKX73", - pin="", - passphrase_protection=False, - label="test", - language="english", - ) - - passphrase_protection = client.debug.read_passphrase_protection() - assert passphrase_protection is False - - address = btc.get_address(client, "Bitcoin", []) - assert address == "128RdrAkJDmqasgvfRf6MC5VcX4HKqH4mR" - - @pytest.mark.setup_client(uninitialized=True) - def test_load_device_xprv_2(self, client): - debuglink.load_device_by_xprv( - client, - xprv="xprv9s21ZrQH143K2JF8RafpqtKiTbsbaxEeUaMnNHsm5o6wCW3z8ySyH4UxFVSfZ8n7ESu7fgir8imbZKLYVBxFPND1pniTZ81vKfd45EHKX73", - pin="", - passphrase_protection=True, - label="test", - language="english", - ) - - client.set_passphrase("passphrase") - - passphrase_protection = client.debug.read_passphrase_protection() - assert passphrase_protection is True - - address = btc.get_address(client, "Bitcoin", []) - assert address == "1CHUbFa4wTTPYgkYaw2LHSd5D4qJjMU8ri"