Merge remote-tracking branch 'agent/benma-agent/btc-root-xpub-m49'
What changed, and why it matters
This firmware update makes two changes to how the BitBox02 hardware wallet handles Bitcoin-related requests. First, it blocks apps from exporting the wallet's master public key (the 'root xpub') at the top-level path 'm/'. Second, it allows signing Bitcoin messages using keypaths that start with 'm/49' (unhardened) for external services, in addition to the already allowed 'm/45'' and 'm/48'' paths. The changelog explicitly frames the root-xpub restriction as a security improvement, while the m/49 change is described as a feature expansion.
Review whether any client software or workflows depend on root xpub export via the Bitcoin API; if so, update them before deploying this firmware. For the m/49 signing change, confirm that unhardened external-service keypaths meet the intended security model, since unhardened derivation leaks child public keys if a parent public key is known.
Security signals we found
Root xpub export blocked at empty keypath (m/)
Changelog describes root-xpub restriction as a security-relevant change
External service message signing expanded to m/49 unhardened purpose
Unit tests added for both new behaviors
Evidence from the diff
The commit modifies the Bitcoin API in the BitBox02 firmware. In src/rust/bitbox02-rust/src/hww/api/bitcoin.rs, the xpub() handler now returns Error::InvalidInput when keypath is empty, preventing export of the master xpub at the root path m/. In src/rust/bitbox02-rust/src/hww/api/bitcoin/signmsg.rs, the list of permitted external-service signing purposes is extended to include 49 (unhardened), alongside 45’ and 48’. Tests are added for both behaviors. The Python test script and CHANGELOG are updated accordingly, and versions.json bumps the firmware version from v9.29.0 to v9.30.0.
Changed components
BitBox02 firmware Bitcoin API xpub exportBitBox02 firmware Bitcoin message signing (signmsg)Python send_message test utilityInspect captured patch +79 / −19
### CHANGELOG.md
@@ -7,6 +7,8 @@ recorded separately.
## Firmware
### Unreleased
+- Reject master xpub exports at `m/` through the Bitcoin API
+- Allow Bitcoin message signing with external service keypaths starting with unhardened `m/49`
### v9.29.0
- Require wallet-owned refund addresses for SwapKit
### py/send_message.py
@@ -1150,7 +1150,7 @@ def sign_testnet() -> None:
sign(bitbox02.btc.TBTC, keypath, script_config)
def sign_external_service(purpose: int) -> None:
- keypath = [purpose + HARDENED, 0 + HARDENED, 0 + HARDENED, 0, 0]
+ keypath = [purpose, 0 + HARDENED, 0 + HARDENED, 0, 0]
script_config = bitbox02.btc.BTCScriptConfig(
simple_type=bitbox02.btc.BTCScriptConfig.P2WPKH
)
@@ -1161,8 +1161,9 @@ def sign_external_service(purpose: int) -> None:
choices = (
("Mainnet", sign_mainnet),
("Testnet", sign_testnet),
- ("External service (m/45')", lambda: sign_external_service(45)),
- ("External service (m/48')", lambda: sign_external_service(48)),
+ ("External service (m/45')", lambda: sign_external_service(45 + HARDENED)),
+ ("External service (m/48')", lambda: sign_external_service(48 + HARDENED)),
+ ("External service (m/49)", lambda: sign_external_service(49)),
)
choice = ask_user(choices)
if callable(choice):
### src/rust/bitbox02-rust/src/hww/api/bitcoin.rs
@@ -97,6 +97,9 @@ async fn xpub(
keypath: &[u32],
display: bool,
) -> Result<Response, Error> {
+ if keypath.is_empty() {
+ return Err(Error::InvalidInput);
+ }
let params = params::get(coin);
let is_unusual =
keypath::validate_xpub(keypath, params.bip44_coin, params.taproot_support).is_err();
@@ -611,6 +614,18 @@ mod tests {
output: Some(Output::XpubType(XPubType::Xpub as _)),
};
+ let mut root_req = req.clone();
+ root_req.keypath.clear();
+ for display in [false, true] {
+ root_req.display = display;
+ let mut mock_hal = TestingHal::new();
+ assert_eq!(
+ process_pub(&mut mock_hal, &root_req).await,
+ Err(Error::InvalidInput)
+ );
+ assert!(mock_hal.ui.screens.is_empty());
+ }
+
// -- Wrong coin: MIN-1
let mut req_invalid = req.clone();
req_invalid.coin = BtcCoin::Btc as i32 - 1;
### src/rust/bitbox02-rust/src/hww/api/bitcoin/signmsg.rs
@@ -25,8 +25,12 @@ const MAX_MESSAGE_SIZE: usize = 1024;
const MAX_KEYPATH_DEPTH: usize = 10;
const EXTERNAL_SERVICE_PURPOSE_M45: u32 = 45 + HARDENED;
const EXTERNAL_SERVICE_PURPOSE_M48: u32 = 48 + HARDENED;
-const EXTERNAL_SERVICE_PURPOSES: [u32; 2] =
- [EXTERNAL_SERVICE_PURPOSE_M45, EXTERNAL_SERVICE_PURPOSE_M48];
+const EXTERNAL_SERVICE_PURPOSE_M49: u32 = 49;
+const EXTERNAL_SERVICE_PURPOSES: [u32; 3] = [
+ EXTERNAL_SERVICE_PURPOSE_M45,
+ EXTERNAL_SERVICE_PURPOSE_M48,
+ EXTERNAL_SERVICE_PURPOSE_M49,
+];
/// Validate a keypath in the external service application namespace.
fn validate_external_service_keypath(keypath: &[u32]) -> Result<(), Error> {
@@ -192,11 +196,9 @@ mod tests {
#[test]
fn test_validate_external_service_keypath() {
- assert!(validate_external_service_keypath(&[EXTERNAL_SERVICE_PURPOSE_M45]).is_ok());
- assert!(validate_external_service_keypath(&[EXTERNAL_SERVICE_PURPOSE_M48]).is_ok());
- assert!(
- validate_external_service_keypath(&[
- EXTERNAL_SERVICE_PURPOSE_M45,
+ for purpose in [45 + HARDENED, 48 + HARDENED, 49] {
+ let keypath = [
+ purpose,
0 + HARDENED,
0,
1 + HARDENED,
@@ -206,9 +208,16 @@ mod tests {
3 + HARDENED,
3,
4,
- ])
- .is_ok()
- );
+ 5,
+ ];
+ for depth in 1..=MAX_KEYPATH_DEPTH {
+ assert!(validate_external_service_keypath(&keypath[..depth]).is_ok());
+ }
+ assert_eq!(
+ validate_external_service_keypath(&keypath),
+ Err(Error::InvalidInput)
+ );
+ }
assert_eq!(
validate_external_service_keypath(&[]),
@@ -223,17 +232,15 @@ mod tests {
Err(Error::InvalidInput)
);
assert_eq!(
- validate_external_service_keypath(&[44 + HARDENED]),
+ validate_external_service_keypath(&[49 + HARDENED]),
Err(Error::InvalidInput)
);
assert_eq!(
- validate_external_service_keypath(&[46 + HARDENED]),
+ validate_external_service_keypath(&[44 + HARDENED]),
Err(Error::InvalidInput)
);
assert_eq!(
- validate_external_service_keypath(
- &[EXTERNAL_SERVICE_PURPOSE_M48; MAX_KEYPATH_DEPTH + 1]
- ),
+ validate_external_service_keypath(&[46 + HARDENED]),
Err(Error::InvalidInput)
);
}
@@ -388,6 +395,41 @@ mod tests {
);
}
+ #[async_test::test]
+ pub async fn test_process_m49() {
+ let request = pb::BtcSignMessageRequest {
+ coin: BtcCoin::Btc as _,
+ script_config: Some(pb::BtcScriptConfigWithKeypath {
+ script_config: Some(pb::BtcScriptConfig {
+ config: Some(Config::SimpleType(SimpleType::P2wpkh as _)),
+ }),
+ keypath: vec![49],
+ }),
+ msg: MESSAGE.as_bytes().to_vec(),
+ host_nonce_commitment: None,
+ };
+
+ mock_unlocked();
+ let mut mock_hal = TestingHal::new();
+ assert_eq!(
+ process(&mut mock_hal, &request).await,
+ Ok(Response::SignMessage(pb::BtcSignMessageResponse {
+ signature: hex!(
+ "470dacd1ec8426cc857ca7fb2b8871e7f1039e5c84a845e680b6b84182271d1834599efeb6406ba234be5d1909059770d1a374988b8ae36293419ab3d9d3a2c101"
+ )
+ .to_vec(),
+ }))
+ );
+ assert_eq!(
+ mock_hal.ui.screens[0],
+ Screen::Confirm {
+ title: "Sign message".into(),
+ body: "Coin: Bitcoin\nExternal service key".into(),
+ longtouch: false,
+ }
+ );
+ }
+
#[async_test::test]
pub async fn test_p2wpkh_long_message_warning() {
let msg = "m".repeat(MAX_CONFIRM_BODY_SIZE + 1);
### versions.json
@@ -1,5 +1,5 @@
{
- "firmware": "v9.29.0",
+ "firmware": "v9.30.0",
"bootloader": "v1.2.3",
"stage0": 3
}Why this scored 43/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.