What changed, and why it matters
This commit adds a warning to Trezor devices when a user tries to export an extended public key (xpub) from a path that is considered risky in a future quantum-computing scenario. It does not block the export, but it makes the user confirm they understand the risk. The affected paths are very shallow ones (less than two derivation levels) and paths used for encryption keys or derived passwords (SLIP-15, SLIP-16, BIP-85). Some well-known third-party uses of shallow paths are allowed without a warning. This is a hardening change, not a fix for an active bug or exploit.
Users should upgrade to a firmware version containing this commit if they want the additional warnings. Developers integrating with Trezor should review whether their xpub export paths are on the allowed-purpose whitelist; if not, their users will see a new warning. No immediate mitigation is required for currently deployed devices because the threat model is future quantum-computing based and the export is not blocked.
Security signals we found
New user-facing warning for xpub export from restricted derivation paths
Restricted paths include SLIP-15, SLIP-16, BIP-85, and paths shorter than two levels
Hardening is explicitly not treated as protection against a quantum attacker
Allowed-purpose whitelist preserves compatibility with third-party workflows
Tests added for both allowed and restricted paths, including confirmation/rejection flows
Changelog entries tagged as .security
Evidence from the diff
The patch introduces is_xpub_export_restricted() in both the Core (Python) and Legacy (C) firmware stacks. A derivation path triggers a warning if it is shorter than depth 2, or if its purpose is 10015 (SLIP-15), 10016 (SLIP-16), or 83696968 (BIP-85). Hardening is ignored in the check. A whitelist of allowed purposes (0, 1, 44, 45, 48, 18241, 1195487518, 1885434739) permits depth-1 exports for specific third-party integrations. The warning is shown via a new UI string: “A quantum computer could use this public key to reveal all keys derived from it.” The user can still continue after seeing the warning. The change is applied to Bitcoin and Cardano public-key export in Core, and to Bitcoin and Ethereum public-key export in Legacy.
Changed components
core/src/apps/bitcoin/get_public_key.pycore/src/apps/cardano/get_public_key.pycore/src/apps/common/paths.pycore/src/trezor/ui/layouts/bolt/__init__.pycore/src/trezor/ui/layouts/caesar/__init__.pycore/src/trezor/ui/layouts/delizia/__init__.pycore/src/trezor/ui/layouts/eckhart/__init__.pylegacy/firmware/crypto.clegacy/firmware/crypto.hlegacy/firmware/fsm.clegacy/firmware/fsm.hlegacy/firmware/fsm_msg_coin.hlegacy/firmware/fsm_msg_ethereum.hInspect captured patch +644 / −127
### core/.changelog.d/+xpub-export-restrictions.security
@@ -0,0 +1 @@
+Warn on xpub export for paths shorter than 2 levels and for SLIP-15, SLIP-16 and BIP-85 paths.
### core/embed/rust/librust_qstr.h
@@ -129,6 +129,7 @@ static void _librust_qstrs(void) {
MP_QSTR_address__title_yours;
MP_QSTR_address__warning_not_yours;
MP_QSTR_address__xpub;
+ MP_QSTR_address__xpub_export_warning;
MP_QSTR_address_details__account_info;
MP_QSTR_address_details__derivation_path;
MP_QSTR_address_details__title_receive_address;
### core/embed/rust/src/translations/generated/translated_string.rs
@@ -1699,7 +1699,8 @@ pub enum TranslatedString {
solana__title_blind_signing = 1315, // "Blind signing"
#[cfg(feature = "universal_fw")]
solana__view_details_in_menu = 1316, // "View details in the menu."
- menu__turn_off = 1317, // {"Bolt": "", "Caesar": "", "Delizia": "", "Eckhart": "Turn off"}
+ address__xpub_export_warning = 1317, // "A quantum computer could use this public key to reveal all keys derived from it."
+ menu__turn_off = 1318, // {"Bolt": "", "Caesar": "", "Delizia": "", "Eckhart": "Turn off"}
}
impl TranslatedString {
@@ -3024,6 +3025,7 @@ impl TranslatedString {
"If you are experiencing timeouts, skip straight to signing in the menu.",
"Blind signing",
"View details in the menu.",
+ "A quantum computer could use this public key to reveal all keys derived from it.",
"",
);
@@ -4347,7 +4349,8 @@ impl TranslatedString {
19174,
19187,
19212,
- 19212,
+ 19292,
+ 19292,
];
#[cfg(all(feature = "debug", not(feature = "universal_fw")))]
@@ -5669,6 +5672,7 @@ impl TranslatedString {
"If you are experiencing timeouts, skip straight to signing in the menu.",
"Blind signing",
"View details in the menu.",
+ "A quantum computer could use this public key to reveal all keys derived from it.",
"",
);
@@ -6992,7 +6996,8 @@ impl TranslatedString {
19174,
19187,
19212,
- 19212,
+ 19292,
+ 19292,
];
#[cfg(all(not(feature = "debug"), feature = "universal_fw"))]
@@ -8314,6 +8319,7 @@ impl TranslatedString {
"If you are experiencing timeouts, skip straight to signing in the menu.",
"Blind signing",
"View details in the menu.",
+ "A quantum computer could use this public key to reveal all keys derived from it.",
"",
);
@@ -9637,7 +9643,8 @@ impl TranslatedString {
19174,
19187,
19212,
- 19212,
+ 19292,
+ 19292,
];
#[cfg(all(not(feature = "debug"), not(feature = "universal_fw")))]
@@ -10959,6 +10966,7 @@ impl TranslatedString {
"If you are experiencing timeouts, skip straight to signing in the menu.",
"Blind signing",
"View details in the menu.",
+ "A quantum computer could use this public key to reveal all keys derived from it.",
"",
);
@@ -12282,7 +12290,8 @@ impl TranslatedString {
19174,
19187,
19212,
- 19212,
+ 19292,
+ 19292,
];
} else if #[cfg(feature = "layout_caesar")] {
@@ -13605,6 +13614,7 @@ impl TranslatedString {
"If you are experiencing timeouts, skip straight to signing in the menu.",
"Blind signing",
"View details in the menu.",
+ "A quantum computer could use this public key to reveal all keys derived from it.",
"",
);
@@ -14928,7 +14938,8 @@ impl TranslatedString {
17300,
17313,
17338,
- 17338,
+ 17418,
+ 17418,
];
#[cfg(all(feature = "debug", not(feature = "universal_fw")))]
@@ -16250,6 +16261,7 @@ impl TranslatedString {
"If you are experiencing timeouts, skip straight to signing in the menu.",
"Blind signing",
"View details in the menu.",
+ "A quantum computer could use this public key to reveal all keys derived from it.",
"",
);
@@ -17573,7 +17585,8 @@ impl TranslatedString {
17300,
17313,
17338,
- 17338,
+ 17418,
+ 17418,
];
#[cfg(all(not(feature = "debug"), feature = "universal_fw"))]
@@ -18895,6 +18908,7 @@ impl TranslatedString {
"If you are experiencing timeouts, skip straight to signing in the menu.",
"Blind signing",
"View details in the menu.",
+ "A quantum computer could use this public key to reveal all keys derived from it.",
"",
);
@@ -20218,7 +20232,8 @@ impl TranslatedString {
17300,
17313,
17338,
- 17338,
+ 17418,
+ 17418,
];
#[cfg(all(not(feature = "debug"), not(feature = "universal_fw")))]
@@ -21540,6 +21555,7 @@ impl TranslatedString {
"If you are experiencing timeouts, skip straight to signing in the menu.",
"Blind signing",
"View details in the menu.",
+ "A quantum computer could use this public key to reveal all keys derived from it.",
"",
);
@@ -22863,7 +22879,8 @@ impl TranslatedString {
17300,
17313,
17338,
- 17338,
+ 17418,
+ 17418,
];
} else if #[cfg(feature = "layout_delizia")] {
@@ -24186,6 +24203,7 @@ impl TranslatedString {
"If you are experiencing timeouts, skip straight to signing in the menu.",
"Blind signing",
"View details in the menu.",
+ "A quantum computer could use this public key to reveal all keys derived from it.",
"",
);
@@ -25509,7 +25527,8 @@ impl TranslatedString {
19450,
19463,
19488,
- 19488,
+ 19568,
+ 19568,
];
#[cfg(all(feature = "debug", not(feature = "universal_fw")))]
@@ -26831,6 +26850,7 @@ impl TranslatedString {
"If you are experiencing timeouts, skip straight to signing in the menu.",
"Blind signing",
"View details in the menu.",
+ "A quantum computer could use this public key to reveal all keys derived from it.",
"",
);
@@ -28154,7 +28174,8 @@ impl TranslatedString {
19450,
19463,
19488,
- 19488,
+ 19568,
+ 19568,
];
#[cfg(all(not(feature = "debug"), feature = "universal_fw"))]
@@ -29476,6 +29497,7 @@ impl TranslatedString {
"If you are experiencing timeouts, skip straight to signing in the menu.",
"Blind signing",
"View details in the menu.",
+ "A quantum computer could use this public key to reveal all keys derived from it.",
"",
);
@@ -30799,7 +30821,8 @@ impl TranslatedString {
19450,
19463,
19488,
- 19488,
+ 19568,
+ 19568,
];
#[cfg(all(not(feature = "debug"), not(feature = "universal_fw")))]
@@ -32121,6 +32144,7 @@ impl TranslatedString {
"If you are experiencing timeouts, skip straight to signing in the menu.",
"Blind signing",
"View details in the menu.",
+ "A quantum computer could use this public key to reveal all keys derived from it.",
"",
);
@@ -33444,7 +33468,8 @@ impl TranslatedString {
19450,
19463,
19488,
- 19488,
+ 19568,
+ 19568,
];
} else if #[cfg(feature = "layout_eckhart")] {
@@ -34767,6 +34792,7 @@ impl TranslatedString {
"If you are experiencing timeouts, skip straight to signing in the menu.",
"Blind signing",
"View details in the menu.",
+ "A quantum computer could use this public key to reveal all keys derived from it.",
"Turn off",
);
@@ -36090,7 +36116,8 @@ impl TranslatedString {
20453,
20466,
20491,
- 20499,
+ 20571,
+ 20579,
];
#[cfg(all(feature = "debug", not(feature = "universal_fw")))]
@@ -37412,6 +37439,7 @@ impl TranslatedString {
"If you are experiencing timeouts, skip straight to signing in the menu.",
"Blind signing",
"View details in the menu.",
+ "A quantum computer could use this public key to reveal all keys derived from it.",
"Turn off",
);
@@ -38735,7 +38763,8 @@ impl TranslatedString {
20453,
20466,
20491,
- 20499,
+ 20571,
+ 20579,
];
#[cfg(all(not(feature = "debug"), feature = "universal_fw"))]
@@ -40057,6 +40086,7 @@ impl TranslatedString {
"If you are experiencing timeouts, skip straight to signing in the menu.",
"Blind signing",
"View details in the menu.",
+ "A quantum computer could use this public key to reveal all keys derived from it.",
"Turn off",
);
@@ -41380,7 +41410,8 @@ impl TranslatedString {
20453,
20466,
20491,
- 20499,
+ 20571,
+ 20579,
];
#[cfg(all(not(feature = "debug"), not(feature = "universal_fw")))]
@@ -42702,6 +42733,7 @@ impl TranslatedString {
"If you are experiencing timeouts, skip straight to signing in the menu.",
"Blind signing",
"View details in the menu.",
+ "A quantum computer could use this public key to reveal all keys derived from it.",
"Turn off",
);
@@ -44025,7 +44057,8 @@ impl TranslatedString {
20453,
20466,
20491,
- 20499,
+ 20571,
+ 20579,
];
}
@@ -44058,6 +44091,7 @@ impl TranslatedString {
(Qstr::MP_QSTR_address__title_yours, Self::address__title_yours),
(Qstr::MP_QSTR_address__warning_not_yours, Self::address__warning_not_yours),
(Qstr::MP_QSTR_address__xpub, Self::address__xpub),
+ (Qstr::MP_QSTR_address__xpub_export_warning, Self::address__xpub_export_warning),
(Qstr::MP_QSTR_address_details__account_info, Self::address_details__account_info),
(Qstr::MP_QSTR_address_details__derivation_path, Self::address_details__derivation_path),
(Qstr::MP_QSTR_address_details__title_receive_address, Self::address_details__title_receive_address),
### core/mocks/trezortranslate_keys.pyi
@@ -25,6 +25,7 @@ class TR:
address__title_yours: str = "(yours)"
address__warning_not_yours: str = "This is NOT your address."
address__xpub: str = "XPUB"
+ address__xpub_export_warning: str = "A quantum computer could use this public key to reveal all keys derived from it."
address_details__account_info: str = "Account info"
address_details__derivation_path: str = "Derivation path"
address_details__title_receive_address: str = "Receive address"
### core/src/apps/bitcoin/get_public_key.py
@@ -43,6 +43,8 @@ async def get_public_key(
if not keychain:
keychain = await get_keychain(curve_name, [paths.AlwaysMatchingSchema])
+ await paths.validate_xpub_export(address_n)
+
node = keychain.derive(address_n)
if (
### core/src/apps/cardano/get_public_key.py
@@ -31,6 +31,7 @@ async def get_public_key(
# path must match the PUBKEY schema
SCHEMA_PUBKEY.match(address_n) or SCHEMA_MINT.match(address_n),
)
+ await paths.validate_xpub_export(address_n)
try:
key = _get_public_key(keychain, address_n)
### core/src/apps/common/paths.py
@@ -4,6 +4,29 @@
HARDENED = const(0x8000_0000)
SLIP25_PURPOSE = const(10025 | HARDENED)
+# Exported xpubs may be broken by a quantum computer, revealing the private key
+# of the node and of its whole subtree. Never export xpubs from subtrees which
+# derive symmetric keys or other quantum-safe secrets from private keys.
+# Hardening is ignored, since it doesn't protect against a quantum attacker.
+_XPUB_EXPORT_DENIED_PURPOSES = (
+ 10015, # SLIP-15: labeling encryption key
+ 10016, # SLIP-16: password manager encryption key
+ 83696968, # BIP-85: derived seeds, keys and passwords
+)
+# Purposes whose depth-1 nodes are exported by third parties despite being
+# shallower than _XPUB_EXPORT_MIN_DEPTH.
+_XPUB_EXPORT_ALLOWED_PURPOSES = (
+ 0, # trezorlib, HWI, Electrum: root fingerprint
+ 1, # Blockstream Green: main multisig account
+ 44, # BTCPay Server vault: fingerprint, passphrase prompt
+ 45, # Casa, Caravan, Nunchuk: BIP-45 multisig
+ 48, # Nunchuk desktop: fingerprint fallback
+ 18241, # Blockstream Green: multisig registration
+ 1195487518, # Blockstream Green: login
+ 1885434739, # Blockstream Green: client secret
+)
+_XPUB_EXPORT_MIN_DEPTH = const(2)
+
if TYPE_CHECKING:
from buffer_types import AnyBytes
from collections.abc import Callable, Collection, Container, Iterable, Sequence
@@ -348,6 +371,26 @@ async def show_path_warning(path: Bip32Path) -> None:
await confirm_path_warning(address_n_to_str(path))
+def is_xpub_export_restricted(path: Bip32Path) -> bool:
+ if path:
+ purpose = unharden(path[0])
+ if purpose in _XPUB_EXPORT_DENIED_PURPOSES:
+ return True
+ if purpose in _XPUB_EXPORT_ALLOWED_PURPOSES:
+ return False
+ return len(path) < _XPUB_EXPORT_MIN_DEPTH
+
+
+async def validate_xpub_export(path: Bip32Path) -> None:
+ """Warn before exporting a restricted xpub."""
+ from trezor.ui.layouts import confirm_xpub_export_warning
+
+ if not is_xpub_export_restricted(path):
+ return
+
+ await confirm_xpub_export_warning(address_n_to_str(path))
+
+
def is_hardened(i: int) -> bool:
return bool(i & HARDENED)
### core/src/trezor/ui/layouts/bolt/__init__.py
@@ -176,6 +176,20 @@ async def confirm_path_warning(path: str, path_type: str | None = None) -> None:
)
+async def confirm_xpub_export_warning(path: str) -> None:
+ with trezorui_api.show_warning(
+ title=TR.address__xpub_export_warning,
+ value=path,
+ description=TR.words__continue_anyway_question,
+ button=TR.buttons__continue,
+ ) as layout:
+ return await raise_if_not_confirmed(
+ layout,
+ "warning_xpub_export",
+ br_code=ButtonRequestType.UnknownDerivationPath,
+ )
+
+
def confirm_multisig_warning() -> Awaitable[None]:
return show_warning(
"warning_multisig",
### core/src/trezor/ui/layouts/caesar/__init__.py
@@ -199,6 +199,16 @@ def confirm_path_warning(
)
+def confirm_xpub_export_warning(path: str) -> Awaitable[None]:
+ return _placeholder_confirm(
+ "warning_xpub_export",
+ TR.words__warning,
+ TR.address__xpub_export_warning,
+ description=path,
+ br_code=ButtonRequestType.UnknownDerivationPath,
+ )
+
+
def confirm_multisig_warning() -> Awaitable[ui.UiResult]:
return show_warning(
"warning_multisig",
### core/src/trezor/ui/layouts/delizia/__init__.py
@@ -173,6 +173,16 @@ def confirm_path_warning(
)
+def confirm_xpub_export_warning(path: str) -> Awaitable[None]:
+ return show_danger(
+ "warning_xpub_export",
+ TR.address__xpub_export_warning,
+ value=path,
+ verb_cancel=TR.buttons__cancel_and_exit,
+ br_code=ButtonRequestType.UnknownDerivationPath,
+ )
+
+
def confirm_multisig_warning() -> Awaitable[None]:
return show_warning(
"warning_multisig",
### core/src/trezor/ui/layouts/eckhart/__init__.py
@@ -142,6 +142,17 @@ def confirm_path_warning(
)
+def confirm_xpub_export_warning(path: str) -> Awaitable[None]:
+ return show_danger(
+ "warning_xpub_export",
+ TR.address__xpub_export_warning,
+ value=path,
+ title=TR.words__important,
+ verb_cancel=TR.buttons__cancel_and_exit,
+ br_code=ButtonRequestType.UnknownDerivationPath,
+ )
+
+
def confirm_multisig_warning() -> Awaitable[None]:
return show_warning(
"warning_multisig",
### core/tests/test_apps.common.paths.py
@@ -32,6 +32,79 @@ def test_path_is_hardened(self):
self.assertFalse(path_is_hardened([0]))
self.assertFalse(path_is_hardened([H_(44), H_(1), H_(0), H_(0), 0]))
+ def test_is_xpub_export_restricted(self):
+ restricted = [
+ [],
+ [2],
+ [H_(3)],
+ [H_(84)],
+ [H_(60)],
+ [1195487519],
+ [H_(4541509)],
+ [H_(10015), H_(0)],
+ [H_(10015), H_(0), 1, 2],
+ [H_(10016), 0],
+ [H_(10016), 0, 0, 0, 0],
+ [10015, 0],
+ [10016, H_(0), 1],
+ [83696968, 2, 0],
+ [H_(83696968)],
+ [H_(83696968), H_(2), H_(0)],
+ [H_(83696968), H_(39), H_(0), H_(12), H_(0)],
+ ]
+ allowed = [
+ [0],
+ [H_(0)],
+ [H_(0), 1],
+ [45],
+ [H_(45)],
+ [1],
+ [H_(1)],
+ [44],
+ [H_(44)],
+ [H_(48)],
+ [H_(18241)],
+ [1195487518],
+ [H_(1885434739)],
+ [H_(45), 0],
+ [H_(45), H_(5)],
+ [1, H_(1)],
+ [H_(84), H_(0)],
+ [H_(44), H_(60)],
+ [H_(3), H_(1)],
+ [4, 255],
+ [1195487518, 6],
+ [H_(4541509), H_(0)],
+ [H_(4541509), H_(1112098098)],
+ [H_(84), H_(0), H_(0)],
+ [H_(44), H_(60), H_(0), 0],
+ [H_(1852), H_(1815), H_(0)],
+ [H_(10025), H_(0), H_(0), H_(1)],
+ ]
+ for path in restricted:
+ self.assertTrue(
+ is_xpub_export_restricted(path),
+ f"Expected {address_n_to_str(path)} to be restricted",
+ )
+ for path in allowed:
+ self.assertFalse(
+ is_xpub_export_restricted(path),
+ f"Expected {address_n_to_str(path)} to be allowed",
+ )
+
+ def test_xpub_export_rule_invariants(self):
+ from apps.common.paths import (
+ _XPUB_EXPORT_ALLOWED_PURPOSES,
+ _XPUB_EXPORT_DENIED_PURPOSES,
+ )
+
+ # A purpose must not be both allowed and denied, otherwise the result
+ # would depend on which list is checked first.
+ self.assertEqual(
+ set(_XPUB_EXPORT_ALLOWED_PURPOSES) & set(_XPUB_EXPORT_DENIED_PURPOSES),
+ set(),
+ )
+
class TestPathSchemas(unittest.TestCase):
def assertMatch(self, schema, path):
### core/translations/en.json
@@ -67,6 +67,7 @@
"Delizia": "XPUB",
"Eckhart": "Public key (XPUB)"
},
+ "address__xpub_export_warning": "A quantum computer could use this public key to reveal all keys derived from it.",
"address_details__account_info": "Account info",
"address_details__derivation_path": "Derivation path",
"address_details__title_receive_address": "Receive address",
### core/translations/order.json
@@ -1316,5 +1316,6 @@
"1314": "solana__skip_details_hint",
"1315": "solana__title_blind_signing",
"1316": "solana__view_details_in_menu",
- "1317": "menu__turn_off"
+ "1317": "address__xpub_export_warning",
+ "1318": "menu__turn_off"
}
### core/translations/signatures.json
@@ -1,8 +1,8 @@
{
"current": {
- "merkle_root": "1873bfdf28e01f78cb3fdbf00d8f7bdc21b4a0e7a9245ad2c44adcde201196c9",
- "datetime": "2026-11-06T16:33:14.669470+00:00",
- "commit": "f05a23d2af32ccb13b27944b0f78f32edc68b55e"
+ "merkle_root": "62f056d35925b24e699f72c35efe56e2fd9a40a679d374d87a50206130b2791b",
+ "datetime": "2026-11-11T12:01:48.951213+00:00",
+ "commit": "006351c05c2527ad385f588af85fe89c10b78f1e"
},
"history": [
{
### legacy/firmware/.changelog.d/+xpub-export-restrictions.security
@@ -0,0 +1 @@
+Warn on xpub export for paths shorter than 2 levels and for SLIP-15, SLIP-16 and BIP-85 paths.
### legacy/firmware/crypto.c
@@ -1092,3 +1092,47 @@ bool descriptor_format(InputScriptType script_type, uint32_t root_fingerprint,
memzero(dest, dest_size);
return false;
}
+
+// Exported xpubs may be broken by a quantum computer, revealing the private
+// key of the node and of its whole subtree.
+bool is_xpub_export_restricted(uint32_t address_n_count,
+ const uint32_t *address_n) {
+ // Never export xpubs from subtrees which derive symmetric keys or other
+ // quantum-safe secrets from private keys. Hardening is ignored, since it
+ // doesn't protect against a quantum attacker.
+ static const uint32_t denied_purposes[] = {
+ 10015, // SLIP-15: labeling encryption key
+ 10016, // SLIP-16: password manager encryption key
+ 83696968, // BIP-85: derived seeds, keys and passwords
+ };
+ if (address_n_count > 0) {
+ uint32_t purpose = address_n[0] & ~PATH_HARDENED;
+ for (size_t i = 0; i < sizeof(denied_purposes) / sizeof(*denied_purposes);
+ i++) {
+ if (purpose == denied_purposes[i]) {
+ return true;
+ }
+ }
+
+ // Purposes whose depth-1 nodes are exported by third parties despite
+ // being shallower than XPUB_EXPORT_MIN_DEPTH.
+ static const uint32_t allowed_purposes[] = {
+ 0, // trezorlib, HWI, Electrum: root fingerprint
+ 1, // Blockstream Green: main multisig account
+ 44, // BTCPay Server vault: fingerprint, passphrase prompt
+ 45, // Casa, Caravan, Nunchuk: BIP-45 multisig
+ 48, // Nunchuk desktop: fingerprint fallback
+ 18241, // Blockstream Green: multisig registration
+ 1195487518, // Blockstream Green: login
+ 1885434739, // Blockstream Green: client secret
+ };
+ for (size_t i = 0; i < sizeof(allowed_purposes) / sizeof(*allowed_purposes);
+ i++) {
+ if (purpose == allowed_purposes[i]) {
+ return false;
+ }
+ }
+ }
+
+ return address_n_count < XPUB_EXPORT_MIN_DEPTH;
+}
### legacy/firmware/crypto.h
@@ -40,6 +40,8 @@
// use and still allow to quickly brute-force the correct bip32 path.
#define PATH_MAX_ADDRESS_INDEX 1000000
#define PATH_SLIP25_PURPOSE (PATH_HARDENED | 10025)
+// Minimum depth of an exported xpub, exceptions in is_xpub_export_restricted()
+#define XPUB_EXPORT_MIN_DEPTH 2
// The number of bip32 levels used in a wallet (chain and address)
#define BIP32_WALLET_DEPTH 2
@@ -110,6 +112,9 @@ bool coin_path_check(const CoinInfo *coin, InputScriptType script_type,
uint32_t address_n_count, const uint32_t *address_n,
bool has_multisig, PathSchema unlock, bool full_check);
+bool is_xpub_export_restricted(uint32_t address_n_count,
+ const uint32_t *address_n);
+
bool is_multisig_input_script_type(InputScriptType script_type);
bool is_multisig_output_script_type(OutputScriptType script_type);
bool is_internal_input_script_type(InputScriptType script_type);
### legacy/firmware/fsm.c
@@ -501,6 +501,23 @@ bool fsm_layoutPathWarning(void) {
return true;
}
+bool fsm_checkXpubExport(uint32_t address_n_count, const uint32_t *address_n) {
+ if (!is_xpub_export_restricted(address_n_count, address_n)) {
+ return true;
+ }
+
+ layoutDialogSwipe(&bmp_icon_warning, _("Abort"), _("Continue"), NULL,
+ _("A quantum computer"), _("could use this key to"),
+ _("reveal all keys"), _("derived from it."),
+ _("Continue at own risk!"), NULL);
+ if (!protectButton(ButtonRequestType_ButtonRequest_UnknownDerivationPath,
+ false)) {
+ fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
+ return false;
+ }
+ return true;
+}
+
bool fsm_layoutDifferentPathsWarning(void) {
layoutDialogSwipe(&bmp_icon_warning, _("Abort"), _("Continue"), NULL,
_("Using different paths"), _("for different XPUBs."), NULL,
### legacy/firmware/fsm.h
@@ -151,6 +151,7 @@ bool fsm_layoutVerifyMessage(const uint8_t *msg, uint32_t len);
bool fsm_layoutPathWarning(void);
bool fsm_layoutDifferentPathsWarning(void);
+bool fsm_checkXpubExport(uint32_t address_n_count, const uint32_t *address_n);
bool fsm_checkCoinPath(const CoinInfo *coin, InputScriptType script_type,
uint32_t address_n_count, const uint32_t *address_n,
bool has_multisig, MessageType message_type,
### legacy/firmware/fsm_msg_coin.h
@@ -56,6 +56,11 @@ void fsm_msgGetPublicKey(const GetPublicKey *msg) {
}
}
+ if (!fsm_checkXpubExport(msg->address_n_count, msg->address_n)) {
+ layoutHome();
+ return;
+ }
+
// Make sure we never display the temporary XPUB to the user.
if (seed != NULL && msg->show_display) {
fsm_sendFailure(FailureType_Failure_DataError,
### legacy/firmware/fsm_msg_ethereum.h
@@ -86,6 +86,14 @@ void fsm_msgEthereumGetPublicKey(const EthereumGetPublicKey *msg) {
return;
}
+ // Unreachable while only m/44' and m/45' subtrees are allowed above, since
+ // both purposes are allowed by is_xpub_export_restricted(). Kept as a
+ // fail-safe in case the restriction above is relaxed.
+ if (!fsm_checkXpubExport(msg->address_n_count, msg->address_n)) {
+ layoutHome();
+ return;
+ }
+
const char *curve = coin->curve_name;
uint32_t fingerprint;
HDNode *node = fsm_getDerivedNode(curve, msg->address_n, msg->address_n_count,
### tests/device_tests/bitcoin/test_getpublickey_path_warning.py
@@ -42,8 +42,9 @@
VECTORS_WARN = ( # path, script_type
# One level deeper is neither the deepest hardened prefix nor the account
pytest.param("m/45h/0", IST.SPENDADDRESS, id="below_casa"),
- # A pattern with no hardened component has no export point
- pytest.param("m/1", IST.SPENDADDRESS, id="unhardened"),
+ # A pattern with no hardened component has no export point (paths shorter
+ # than 2 levels are restricted, see test_getpublickey_restricted.py)
+ pytest.param("m/1/2", IST.SPENDADDRESS, id="unhardened"),
)
### tests/device_tests/bitcoin/test_getpublickey_restricted.py
@@ -0,0 +1,110 @@
+# This file is part of the Trezor project.
+#
+# Copyright (C) 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 <https://www.gnu.org/licenses/lgpl-3.0.html>.
+
+"""Restricted xpub export shows a warning, regardless of safety checks:
+paths shorter than 2 levels and SLIP-15, SLIP-16 and BIP-85 subtrees, except
+for depth-1 nodes used by third parties. Hardening is ignored."""
+
+import pytest
+
+from trezorlib import btc, device, messages
+from trezorlib.debuglink import DebugSession as Session
+from trezorlib.debuglink import TrezorTestContext
+from trezorlib.exceptions import Cancelled
+from trezorlib.tools import parse_path
+
+from ...common import MOCK_GET_ENTROPY, is_core
+from ...input_flows import InputFlowConfirmAllWarnings
+from ...input_flows_helpers import BackupFlow
+
+# The classification of individual paths is covered by
+# test_is_xpub_export_restricted in core/tests/test_apps.common.paths.py. These
+# tests only cover the wiring in the handlers and the confirmation flow.
+
+
+def test_allowed(session: Session):
+ with session.test_ctx as client:
+ client.set_expected_responses([messages.PublicKey])
+ res = btc.get_public_node(session, parse_path("m/0h"))
+ assert res.xpub
+
+
+_WARNING = messages.ButtonRequest(code=messages.ButtonRequestType.UnknownDerivationPath)
+
+
+def _confirm_warnings(session: Session, client: TrezorTestContext) -> None:
+ if is_core(session):
+ IF = InputFlowConfirmAllWarnings(session)
+ client.set_input_flow(IF.get())
+
+
+def _get_confirmed(session: Session, path: str) -> messages.PublicKey:
+ with session.test_ctx as client:
+ _confirm_warnings(session, client)
+ client.set_expected_responses([_WARNING, messages.PublicKey])
+ return btc.get_public_node(session, parse_path(path))
+
+
+def test_restricted_confirmed(session: Session):
+ res = _get_confirmed(session, "m/10016h/0")
+ assert res.xpub
+
+
+def test_restricted_rejected(session: Session):
+ with session.test_ctx as client, pytest.raises(Cancelled):
+ client.set_expected_responses(
+ [_WARNING, messages.Failure(code=messages.FailureType.ActionCancelled)]
+ )
+
+ def input_flow():
+ yield
+ session.debug.press_no()
+
+ client.set_input_flow(input_flow())
+ btc.get_public_node(session, parse_path("m"))
+
+
+@pytest.mark.setup_client(uninitialized=True)
+def test_entropy_check_restricted(session: Session):
+ # Restricted xpubs show the warning during the entropy check too. Rejecting
+ # it aborts the whole reset on core and fails the request on legacy.
+ with session.test_ctx as client:
+
+ def input_flow():
+ if is_core(session):
+ yield from BackupFlow(client).confirm_new_wallet()
+ while True:
+ br = yield
+ if br.code == messages.ButtonRequestType.UnknownDerivationPath:
+ session.debug.press_no()
+ return
+ session.debug.press_yes()
+
+ client.set_input_flow(input_flow())
+ with pytest.raises(Cancelled):
+ device.setup(
+ session,
+ strength=128,
+ entropy_check_count=1,
+ paths=[parse_path("m/84h")],
+ backup_type=messages.BackupType.Bip39,
+ skip_backup=True,
+ pin_protection=False,
+ passphrase_protection=False,
+ _get_entropy=MOCK_GET_ENTROPY,
+ )
+ session.refresh_features()
+ assert session.features.initialized is False
### tests/device_tests/bitcoin/test_nonstandard_paths.py
@@ -108,16 +108,32 @@
)
+def _get_public_node(
+ session: Session, path: str, **kwargs: object
+) -> messages.PublicKey:
+ # Paths shorter than 2 levels show an xpub export warning, see
+ # test_getpublickey_restricted.py.
+ with session.test_ctx as client:
+ if is_core(session):
+ IF = InputFlowConfirmAllWarnings(session)
+ client.set_input_flow(IF.get())
+ return btc.get_public_node(
+ session, parse_path(path), coin_name="Bitcoin", **kwargs
+ )
+
+
+def _get_public_nodes(session: Session, paths: list[str]) -> list[messages.HDNodeType]:
+ return [_get_public_node(session, path).node for path in paths]
+
+
# Has AlwaysMatchingSchema but let's make sure the nonstandard paths are
# accepted in case we make this more restrictive in the future.
@pytest.mark.parametrize("path, script_types", VECTORS)
def test_getpublicnode(
session: Session, path: str, script_types: list[messages.InputScriptType]
):
for script_type in script_types:
- res = btc.get_public_node(
- session, parse_path(path), coin_name="Bitcoin", script_type=script_type
- )
+ res = _get_public_node(session, path, script_type=script_type)
assert res.xpub
@@ -210,13 +226,8 @@ def test_getaddress_multisig(
session: Session, paths: list[str], address_index: list[int]
):
pubs = [
- messages.HDNodePathType(
- node=btc.get_public_node(
- session, parse_path(path), coin_name="Bitcoin"
- ).node,
- address_n=address_index,
- )
- for path in paths
+ messages.HDNodePathType(node=node, address_n=address_index)
+ for node in _get_public_nodes(session, paths)
]
multisig = messages.MultisigRedeemScriptType(pubkeys=pubs, m=2)
@@ -240,13 +251,8 @@ def test_getaddress_multisig(
@pytest.mark.parametrize("paths, address_index", VECTORS_MULTISIG)
def test_signtx_multisig(session: Session, paths: list[str], address_index: list[int]):
pubs = [
- messages.HDNodePathType(
- node=btc.get_public_node(
- session, parse_path(path), coin_name="Bitcoin"
- ).node,
- address_n=address_index,
- )
- for path in paths
+ messages.HDNodePathType(node=node, address_n=address_index)
+ for node in _get_public_nodes(session, paths)
]
signatures = [b""] * 3
multisig = messages.MultisigRedeemScriptType(
### tests/device_tests/test_protection_levels.py
@@ -241,7 +241,7 @@ def test_get_public_key(client: Client):
)
session = client.get_session()
- session.call(messages.GetPublicKey(address_n=[]))
+ session.call(messages.GetPublicKey(address_n=parse_path("m/44h/0h/0h")))
def test_get_address(client: Client):
### tests/ui_tests/fixtures.json
[binary or diff unavailable]Why this scored 46/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.